How to get a handle to a brush object for GDI
-
Hi, I'm very new to C# and .NET so sorry if this question sounds really stupid, but how could I get a handle (or pointer) to a brush object in C#. :doh: I'm trying to use gdi32.dll's FrameRgn to add a frame to an irregular borderless form. One of the parameters to the method is a brush handle. I've googled this but I could only see VB.NET examples of codes using FrameRgn. :( Thanks to anyone who can help.
-
Hi, I'm very new to C# and .NET so sorry if this question sounds really stupid, but how could I get a handle (or pointer) to a brush object in C#. :doh: I'm trying to use gdi32.dll's FrameRgn to add a frame to an irregular borderless form. One of the parameters to the method is a brush handle. I've googled this but I could only see VB.NET examples of codes using FrameRgn. :( Thanks to anyone who can help.
-
You do exactly as they do in VB.NET. The entire framework is the same, it's just the language syntax that differs.
--- single minded; short sighted; long gone;
Ha ha ha... I read your response before having breakfast ;) I should have clarified my question: The VB example I saw has this line:
Dim hBrush As Long
hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 255, 0))
I could not find Create_AnyTypeOf_Brush in the VS HelpIndex nor the Object Browser. Which namespace/dll/assembly does this method belong to? Or should I use a similar/different method in C#. The website I saw the above example from tells you to buy a book to get more info on the above example. I already inserted System.Runtime.InteropServices in my using statements (based on another website I saw). I could not translate the above code to C#. I already have been able to import the FrameRgn method from gdi32.dll, but I'm stuck with the above line of code. Please help, anybody. :( Thanks very much -- modified at 21:55 Thursday 20th September, 2007 -
Ha ha ha... I read your response before having breakfast ;) I should have clarified my question: The VB example I saw has this line:
Dim hBrush As Long
hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 255, 0))
I could not find Create_AnyTypeOf_Brush in the VS HelpIndex nor the Object Browser. Which namespace/dll/assembly does this method belong to? Or should I use a similar/different method in C#. The website I saw the above example from tells you to buy a book to get more info on the above example. I already inserted System.Runtime.InteropServices in my using statements (based on another website I saw). I could not translate the above code to C#. I already have been able to import the FrameRgn method from gdi32.dll, but I'm stuck with the above line of code. Please help, anybody. :( Thanks very much -- modified at 21:55 Thursday 20th September, 2007CreateHatchBrush is a GDI method: MSDN Library: CreateHatchBrush[^] A search on pinvoke.net[^] gave this declaration:
static extern IntPtr CreateHatchBrush(int fnStyle, uint clrref);
A search for "C# CreateHatchBrush"[^] gave a page as the first hit containing this code:[DllImport("gdi32")] public static extern int CreateHatchBrush(int nIndex, int crColor)
--- single minded; short sighted; long gone;
-
CreateHatchBrush is a GDI method: MSDN Library: CreateHatchBrush[^] A search on pinvoke.net[^] gave this declaration:
static extern IntPtr CreateHatchBrush(int fnStyle, uint clrref);
A search for "C# CreateHatchBrush"[^] gave a page as the first hit containing this code:[DllImport("gdi32")] public static extern int CreateHatchBrush(int nIndex, int crColor)
--- single minded; short sighted; long gone;
Thanks Guffa. I should have known the method is from the same dll. But when I added the methods and passed the value returned by CreateSolidBrush to FrameRgn, it still wasn't drawing the border. I'm passing the right values to CreateSolidBrush but I think I'm passing some wrong info to FrameRgn. I didn't want to spend anymore time on it. So I decided to just draw the border myself using the same graphicspath I'm using to clip the region. I just used a slightly thick pen so it still shows after the clipping. Simpler and less hassle. Cheers.