Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to get a handle to a brush object for GDI

How to get a handle to a brush object for GDI

Scheduled Pinned Locked Moved C#
csharpgraphicshelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Frank Fajardo
    wrote on last edited by
    #1

    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.

    G 1 Reply Last reply
    0
    • F Frank Fajardo

      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.

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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;

      F 1 Reply Last reply
      0
      • G Guffa

        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;

        F Offline
        F Offline
        Frank Fajardo
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • F Frank Fajardo

          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

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          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;

          F 1 Reply Last reply
          0
          • G Guffa

            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;

            F Offline
            F Offline
            Frank Fajardo
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups