Heres how to fix it:
Workaround 1:
Currently a workaround here is that we may put the nested child
GroupBoxes into a Panel. Since the Panel is invisible, this can have the
same visual effect.
Workaround 2:
Derive from the GroupBox class and override its WndProc function to
process the ¡°WM_PRINTCLIENT¡± message correctly:
//Please add the following using statement:
using System.Runtime.InteropServices;
public class FixedGroupBox : GroupBox
{
[DllImport("User32.dll", ExactSpelling = true, CharSet =
CharSet.Auto)]
public static extern bool GetClientRect(HandleRef hWnd, [In,
Out] ref RECT
rect);
private const int WM_PRINTCLIENT = 0x0318;
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public RECT(System.Drawing.Rectangle r)
{
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
public static RECT FromXYWH(int x, int y, int width, int
height)
{
return new RECT(x, y, x + width, y + height);
}
public System.Drawing.Size Size
{
get
{
return new
System.Drawing.Size(this.right - this.left, this.bottom - this.top);
}
}
}
private void WmPrintClient(ref Message m)
{
RECT rect = new RECT();
GetClientRect(new HandleRef(this, Handle), ref rect);
Graphics graphics = Graphics.FromHdc(m.WParam);
Brush b = new SolidBrush(BackColor);
graphics.FillRectangle(b, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top);
graphics.Dispose();
b.Dispose();
m.Result = (IntPtr)1;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PRINTCLIENT:
WmPrintClient(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
}