We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I draw on a GridControl''s border?

Judging by my tests with the gridcontrol''s ClientRectangle property and after looking thru the FAQs, I deduce that the borders for GridControls are drawn outside of the client area. But say I want to draw over the borders for whatever reason. How do I go about getting a graphics object that will let me draw over these borders?

4 Replies

MC Martin Cyr July 7, 2005 03:12 PM UTC

Take a look at the DrawCurrentCellBorder event. Hope it helps

AD Administrator Syncfusion Team July 7, 2005 04:35 PM UTC

I am not sure I understand your needs. You can use grid.CreateGraphics to create a Graphics object for a grid (like any control).

AD Administrator Syncfusion Team July 7, 2005 04:57 PM UTC

>I am not sure I understand your needs. > >You can use grid.CreateGraphics to create a Graphics object for a grid (like any control). This is what I attempted to do, but the resulting Graphics object will not let me draw on the control border. I think this is because the control border is drawn on the non-client area of the GridControl and grid.CreateGraphics only returns a Graphics object for the client area of the control. I''ve done more research and I think I have to handle the WM_NCCALCSIZE and WM_NCPAINT messages in WndProc to be able to draw on the border of the grid control.

AD Administrator Syncfusion Team July 8, 2005 06:34 PM UTC

I managed to get it working, but with a slightly different way. Instead of handling the WM_NCPAINT message, I handled WM_PAINT in WndProc, let the control draw itself, then draw over the border. However, I had to do one important thing before this would work. Instead of relying on Me.CreateGraphics, which apparently only returns the client area, I had to instead get the DC of the control, then create a graphics object from that. I had to use two API methods because I could not find the Managed equivalents. Here are the important parts of the code: Friend Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal ByValhwnd As IntPtr) As IntPtr Friend Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As Integer After trapping the WM_PAINT message in WndProc, call a method that does something like this: Dim hDC As IntPtr Try Dim g As Graphics '' Get the DC for the control hDC = Win32APIMethods.GetWindowDC(ctrl.Handle) '' Create a Graphics object for the control '' NOTE: This differs from Me.CreateGraphics in that it allows you to draw on the non-client area g = Graphics.FromHdc(hDC) '' Draw the border ... '' Clean up g.Dispose() Catch ex As Exception '' Do whatever Finally '' Release the DC If Not hDC.Equals(IntPtr.Zero) Then Win32APIMethods.ReleaseDC(ctrl.Handle, hDC) End Try

Live Chat Icon For mobile
Up arrow icon