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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:





31444 Jul 7,2005 02:30 PM UTC Jul 8,2005 06:34 PM UTC WinForms 4
Tags: GridControl
Administrator [Syncfusion]
Asked On July 7, 2005 02:30 PM UTC

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?

Martin Cyr
Replied On July 7, 2005 03:12 PM UTC

Take a look at the DrawCurrentCellBorder event. Hope it helps

Administrator [Syncfusion]
Replied On 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).

Administrator [Syncfusion]
Replied On 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.

Administrator [Syncfusion]
Replied On 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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon