Child control in non client area ?

  • Thread starter Thread starter cadilhac
  • Start date Start date
C

cadilhac

Hi,

is it possible to create and display a control (a toolbar in my case)
in the non client area of a parent control ? I want this to avoid
taking into account the toolbar while drawing in the parent custom
control.
I write in C#.

Thanks for your help

Herve
 
Hi Herve,

To draw a control in nonclient area, you need to use suitable Win32 API
calls.
For example, by trapping the appropriate WM_NC* messages, you could draw a
custom rectangle.

IntPtr hDC = GetWindowDC(Handle);

try
{
using (Graphics grfx = Graphics.FromHdc(hDC))
{
Rectangle rect = new Rectangle(0, 0, Width, Height);
// Note - BorderWidth is a custom property
// whose value is the nonclient frame width
ControlPaint.DrawBorder(grfx, rect,
BackColor, BorderWidth, ButtonBorderStyle.Solid,
BackColor, BorderWidth, ButtonBorderStyle.Solid,
BackColor, BorderWidth, ButtonBorderStyle.Solid,
BackColor, BorderWidth, ButtonBorderStyle.Solid);
}
}
finally
{
ReleaseDC(Handle, hDC);
}


You can also override WndProc and process WM_NCPAINT (0x0085) or any other
windows message you need.

Here's a post that shows how to do it:
http://groups-beta.google.com/group....dotnet.*&start=10&hl=en&lr=&ie=UTF-8&rnum=13

HTH,
Anushi
 
Back
Top