|
Hello,
I have a form that is shaped with a GraphicsPath object. After setting the form's region, my form's border looks bad (jagged edges). I would like a nice solid border around the form. Is there something I can do?
I have tried using the TransparencyKey property to fill my form with a color. This works fine, except it doesn't work at 32 bits (a bug in TransparencyKey) and I can't use AntiAliasing for my border.
Is there any way I can get smooth, soft edges on my custom shaped form using a GraphicsPath?
Thanx for the help,
-Flack
|
|
|
|
|
use a bitmap as a region, graphics software can draw stuff better than we can do in code usually
|
|
|
|
|
What's your target platform? If it's Windows 2000 and later, you can use layered windows (of which TransparencyKey partly encapsulates, and is - as you've experienced/read - buggy). You can perform the layered windows yourself, though, and get a nice smooth edge like you see with Windows Media Player 9 or the splash screens for newer Adobe applications.
See the SetLayeredWindowAttributes native API documentation in the Platform SDK. You can P/Invoke this. Also see the "Using Layered Windows" link at the bottom. Also, override CreateParams , get base.CreateParams , and OR the WS_EX_LAYERED (0x00080000) extended style, returning the modified CreateParams from your override. You can achieve all this through managed code, but there's a bug in there somewhere and I honestly can't remember where. I do know that doing the work mentioned above has worked for me in .NET applications previously.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've got an object that i am writing a re-sizing method for. The resize begins upon mouse down when over a certain area of a component. This works fine, i can create an increasing side, but only on a per click basis.
The element that activates the re-size is part of the component, and not tied to the parent form. What I need to do is detect the movement of the mouse as an event, either inwards or out of the component, and use the difference in the X coordinates for horizontal re-sizing, and the difference in the Y coordinates for vertical re-sizing.
I thought i had this figured, but guess I was wrong.
Cata
|
|
|
|
|
Without any code example, we can only guess at what you doing wrong, but...
Are you doing your resize in the MouseMove handler or MouseDown. Use MouseMove and check for the position of the mouse, then if your in the resize area, check the status of the MouseButtons in the MouseEventsArgs, then you can use that to determine if you should resize or not.
RageInTheMachine9532
|
|
|
|
|
...or like I said originally today, set a flat in the MouseDown handler and reset it in the MouseUp handler. Dave's method would work, but you end up having to check the same condition (which makes several calls) with each execution of the handler, which is slightly less efficient than using a simple flag.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi.
How could I implement a pointer to an array of bytes, (bytes[]) in C#?
Thank you.
|
|
|
|
|
You can use something like
unsafe
{
byte* bytes = stackalloc byte[50];
}
The stackalloc keyword puts the bytes on the stack as opposed to the heap, and therefore not subject to garbage collection. If you don't use stackalloc, be sure to use the fixed keyword to pin the bytes to the heap (so that the GC won't clean them up).
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
Yeah.
But how can asign to this pointer an array like byte[].
Simply byte= myarray[0]; ?
Thank.
|
|
|
|
|
I believe you have to assign it using the fixed keyword.
byte[] managedByteArr = new byte[50];
managedByteArr[0] = 200;
fixed (byte* pBytes = managedByteArr)
{
Console.WriteLine(pBytes[0]);
}
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
But when the pointer bytes is a member variable of the class throw a compiler error: "Identifier expected" here:
fixed(pBytes=arraymanaged) <-here
{
.....
}
The pointer must be a member variable, that's what I need, so, I can get data out from a thread that call some function that return an array of bytes, (byte[]).
Do you understand what I need?
Thank you.
|
|
|
|
|
This is the code that I wrote:
using System;
unsafe class Class1
{
public byte* pBytes;
unsafe static void Main()
{
byte[] mArr= new byte[]{6,9,11,25};
fixed (pBytes = mArr)
{
for(int i= 0; i<4;i++)
Console.WriteLine(pBytes[i]);
}
}
}
|
|
|
|
|
Not that your example is any indication of what you are actually doing, but keep in mind that C# does turn off bounds checking for cases like
for(int i=0; i
|
|
|
|
|
Why do you need to use an unsafe context for this? mArr is your "pointer" to the array of bytes, except that in the managed code world it's called references, which can be moved around by the garbage collector (GC) in the heap whenever it needs to optimize memory (which is why you must use the fixed keyword, or the GCHandle class to lock the object on the heap for that context). Arrays are also reference types, so you don't need to use ref or out with them except in some uncommon cases when you need to declare an undimensioned array and have a method (not "function") return it.
The code can simply be:
byte[] mArr = new byte[] {6, 9, 11, 25};
for (int i=0; i<mArr.Length; i++)
Console.WriteLine("0x{0:x2}", mArr[i]); Much easier, and correct (since unsafe contexts cause security problems in non-local deployments and are not completely managed by the CLR).
Even if this is a field in your class, it doesn't matter:
public class MyClass
{
public byte[] bytes;
public MyClass()
{
bytes = new byte[] {6, 9, 11, 25};
}
} Your declaration of the byte[] array doesn't dimension it; it only declares an array of a certain type. In unmanaged code, the same is true, since a char* points to the first element (the pointer to the array itself) of a char[] , for example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, that's ok.
But I still having troubles to fill a member field, (array of bytes), with the data returned by a function called from a thread.
Example:
<br />
class myClass<br />
{<br />
public Array m_arr;
<br />
public void MyThreadMethod()<br />
{<br />
object ret; <br />
ret=AFunction(Aparam);
Array ar = (Array) ret;
m_arr=ar;
}
I can't fill my member variable with data of the thread.
Regards.
|
|
|
|
|
You typically don't declare an Array , but an array of something like byte[] , which I mentioned before. This does not have dimension.
Also, why not return the actual array from AFunction ? All this casting is completely unnecessary. So long as this is all .NET code, you can pass and return anything, but you must understand the difference between value and reference types (you're dealing with reference types here). If AFunction is a P/Invoke method, then things are a bit different. Is this the case?
If it's all coded for .NET (no P/Invoke or COM interop), you could simply use m_arr = AFunction(Aparam); it the method was declared appropriately. Return an object or taking an object as a param is really only a good idea when you don't know what to expect (or in some polymorphic designs when derivative classes will accept different types).
The only times when assign data from a thread is a problem is when 1) you don't lock your resource and multiple threads write to it/assign at the same time, or 2) when you try to update the UI (like setting the Text property of a control or adding a ListViewItem to a ListView ). For this latter case, make use of the Control.InvokeRequired property (to determine if the following method should be used) and the Control.Invoke method.
In any case, this should definitely work if its purely managed code. I do it all the time. Please provide more information (and accurate to your actual problem, instead of an example that might not be close enough to your real problem to solve it) about how this method is threaded and what AFunction is (or whatever it is in your code).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!.
Yes, AFunction(AParam) is a method from a ActiveX writing in C++.
A reference to this activex is passed to the constructor of the class.
Maybe this is the problem.
Thank you very much.
|
|
|
|
|
It may be. What's the threading model for the ActiveX control?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am writing a webservice that allows a user to upload files. i had no problem handling pictures but i am having trouble handling plain text files.
How do I write out my stream to a text file that the webservice receives from the client? HOw do I take my System.IO.Stream and pass it into a FileStream so that I can write the file anywhere I want on the server?
Thanks in advance
|
|
|
|
|
Pass the Stream into the constructor of a StreamReader , then buffer the input (in blocks, for which 4096 is a good size typically) to a TextWriter derivative (perhaps a StreamWriter with a FileStream passed to its constructor that points at the right place. This will also allow you to change the encoding if you like.
You could skip the readers and writers, though, and just buffer the input directly from the Stream to a FileStream , something like:
private void Save(Stream s)
{
FileStream file = new FileStream("c:\temp\file.txt", ...);
using (file)
{
byte[] buffer = new byte[4096];
int read = 0;
read = s.Read(buffer, 0, buffer.Length);
while (read != 0)
{
file.Write(buffer, 0, read);
read = s.Read(buffer, 0, buffer.Length);
}
}
} A very simplistic example, but you should get the idea. The code would be similar using a TextReader and TextWriter derivative, but would allow you to more easily handle text as opposed to binary data (although you could still get an encoded string at any time using the Encoding class derivatives).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to access files that are currently in use by another program? I am sure that there is because backup utilities do it all the time, but I just have no idea how to do it. I would really appreciate any help. Thanks
|
|
|
|
|
It depends on the share locks. If a program locks the file for writing, then other programs can read it. If it locks it for reading, the other apps may be able to write to it. If it's locked for both (exclusive), then you'll have to wait.
See the documentation for FileStream class in the .NET Framework, which includes samples. Also see the FileShare enumeration documentation as well.
Backups are an entirely different story and this is a very low-level feature. Also, backup accounts typically (and should) have the backup security privilege that lets those accounts do much more than allowed by other accounts (including administrative accounts if they don't have those privileges.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi folks,
I'm a .net newbie and an wondering if something like this is possible in C# and .net:
I have an abstract class:
abstract public class AbstractDAO {
abstract public int Create(object obj);
...
}
And a concrete class that extends it:
public class BidDAO : AbstractDAO {
public override int Create(Bid bid) { ... };
...
}
this generates a build error because Create(Bid bid) does not effectively override Create(object obj).
The problem goes away if I change the concrete class to:
public class BidDAO : AbstractDAO {
public override int Create(object obj) { Bid bid; bid = (Bid) obj; ... };
...
}
Is there anyway around this? Or perhaps a better question is, is this the *correct* way of doing this?
Any help is much appreciated!
Ed.
|
|
|
|
|
That's one way of doing it, but don't just assume that obj is a Big . Do some type checking first, and throw an ArgumentException if the type is wrong. You could make it as simple as:
public override in Create(object obj)
{
Bid bid = obj as Big;
if (bid == null) throw new ArgumentException("Must pass a Bid object.",
"obj");
} If you want to provide typed parameters, overload Create and just have each of them call one of the Create methods that takes all parameters into account and actually contains the definition of the method.
If you don't want developers to see the overridden method, you can attribute the method with the EditorBrowsableAttribute , passing EditorBrowsableState.Never in the constructor. This doesn't mean it can't be executed, just that compliant code editors (like VS.NET) won't show it in IntelliSense.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is it possible to give the end user on the web based application the cabapility of crystal report or any other tool editor inerface, where s/he can pick the fields they want, lignment, grouping etc. and generate report dinamically?
Thanks,
|
|
|
|
|