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?
Take a look at the DrawCurrentCellBorder event.
Hope it helps
ADAdministrator Syncfusion Team July 7, 2005 11:35 AM
I am not sure I understand your needs.
You can use grid.CreateGraphics to create a Graphics object for a grid (like any control).
ADAdministrator Syncfusion Team July 7, 2005 11:57 AM
>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.
ADAdministrator Syncfusion Team July 8, 2005 01:34 PM
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
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
Catch ex As Exception
'' Do whatever
'' Release the DC
If Not hDC.Equals(IntPtr.Zero) Then Win32APIMethods.ReleaseDC(ctrl.Handle, hDC)