Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom Border Problems

28 views
Skip to first unread message

Shawn B.

unread,
Apr 24, 2006, 3:30:43 AM4/24/06
to
Greetings,

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


Shawn B.

unread,
Apr 25, 2006, 3:16:30 AM4/25/06
to
No answer? I'm still trying to figure this thing out. I get the border but
then it gets painted over after the WM_NCPAINT event completes.


Thanks,
Shawn


Mick Doherty

unread,
Apr 25, 2006, 11:21:09 AM4/25/06
to
I didn't see your original message and so don't know what you've tried, but
here's the code I use in WndProc() to handle the WM_NCPAINT message.


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...

Shawn B.

unread,
Apr 26, 2006, 1:41:53 AM4/26/06
to
I solved this problem by adding a BorderStyle. I was saying
BorderStyle.None; in which case there was no nonclient area to paint in. By
changing to BorderStyle.Fixed3D, I am able to paint the DrawBorder3D inside
the NonClient area and things work the way I want (most of the time).

Thanks,
Shawn


0 new messages