I'm creating a custom control that should paint a custom border from the
DrawBorder3D method. I'm subclassing WndProc and capturing the WM_NCPAINT
message as follows (pardon my brevity):
public event System.Windows.Forms.PaintEventHandler NonClientPaint;
protected virtual void onNonClientPaint(object sender, PaintEventArgs pe)
{
if (this.NonClientPaint != null)
NonClientPaint(sender, pe);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.HWnd != this.Handle)
{
return;
}
switch (m.Msg)
{
case User32.WM_NCPAINT:
IntPtr hDC = User32.GetWindowDC(m.HWnd);
Graphics g = Graphics.FromHdc(hDC);
Rectangle rect = this.ClientRectangle;
PaintEventArgs pe = new PaintEventArgs(g, rect);
onNonClientPaint(this, pe);
User32.ReleaseDC(m.HWnd, hDC);
g.Dispose();
m.Result = IntPtr.Zero;
break;
}
}
In the derived control, I am consuming the WM_NCPAINT event as follows:
protected override void onNonClientPaint(object sender, PaintEventArgs pe)
{
ControlPaint.DrawBorder3D(pe.Graphics, 0, 0, Width, Height, Border);
base.onNonClientPaint(sender, pe);
}
The border is being painted but when my user control draws the Scrollbars
they are drawn on top of the order and when the control pains it is actually
painting on top of the border.
What must I do to cause the scrollbars to be painted inside the border and
the control itself to draw insider the border (yes, I'm already adjusting
the clientrect to the appropriate dimensions (I thought so, anyway).
Thanks,
Shawn
Thanks,
Shawn
Case WM_NCPAINT
NCPaint(m.WParam)
MyBase.DefWndProc(m)
DeleteObject(m.WParam) 'This Deletes the ClipRegion to prevent GDI
leaks.
m.Result = New IntPtr(1)
My NCPaint function uses/updates the ClipRegion passed in by m.WParam. If
m.WParam is 1 then the entire NonClientArea needs repainting otherwise it is
a handle to a Region (hRegion).
Non Client Painting can get quite complex and depending upon what you want
to do can involve using GDI instead of GDI+, but generally only if the
control is likely to be sitting on a translucent form.
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Shawn B." <lea...@html.com> wrote in message
news:%23BI4vgD...@TK2MSFTNGP03.phx.gbl...
Thanks,
Shawn