D
Dan Burby
I myself have been looking for the answer to this, and tonight it finally
dawned on me. The 3d edge on the MdiClient is an extended window style,
WS_EX_CLIENTEDGE. To change an extended style, we need to know the
original extended style used by a window. To get that, call GetWindowLong.
Next we need to call SetWindowLong to change the extended style (remove
the ws_ex_clientedge style). Finally, the extended styles are "cached" as
explained on the msdn website, so to make the control repaint itself
properly, you need to call SetWindowPos to notify the control that its
edges have changed. Below is the code needed:
[DllImport("user32")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int
X, int Y, int cx, int cy, int uFlags);
const int GWL_EXSTYLE = (-20);
const int WS_EX_CLIENTEDGE = 0x00000200;
const int SWP_FRAMECHANGED = 0x0020;
const int SWP_NOSIZE = 0x0001;
const int SWP_NOMOVE = 0x0002;
const int SWP_NOZORDER = 0x0004;
.... and then in the forms constructor (after InitializeComponent) ...
MdiClient mdi = null;
int ExStyle;
foreach(Control ctl in Controls)
{
if(ctl is MdiClient)
{
mdi = (MdiClient)ctl;
mdi.BackColor = this.BackColor;
ExStyle = GetWindowLong(mdi.Handle, GWL_EXSTYLE);
ExStyle ^= WS_EX_CLIENTEDGE;
SetWindowLong(mdi.Handle, GWL_EXSTYLE, ExStyle);
SetWindowPos(mdi.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE |
SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
}
dawned on me. The 3d edge on the MdiClient is an extended window style,
WS_EX_CLIENTEDGE. To change an extended style, we need to know the
original extended style used by a window. To get that, call GetWindowLong.
Next we need to call SetWindowLong to change the extended style (remove
the ws_ex_clientedge style). Finally, the extended styles are "cached" as
explained on the msdn website, so to make the control repaint itself
properly, you need to call SetWindowPos to notify the control that its
edges have changed. Below is the code needed:
[DllImport("user32")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32")]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int
X, int Y, int cx, int cy, int uFlags);
const int GWL_EXSTYLE = (-20);
const int WS_EX_CLIENTEDGE = 0x00000200;
const int SWP_FRAMECHANGED = 0x0020;
const int SWP_NOSIZE = 0x0001;
const int SWP_NOMOVE = 0x0002;
const int SWP_NOZORDER = 0x0004;
.... and then in the forms constructor (after InitializeComponent) ...
MdiClient mdi = null;
int ExStyle;
foreach(Control ctl in Controls)
{
if(ctl is MdiClient)
{
mdi = (MdiClient)ctl;
mdi.BackColor = this.BackColor;
ExStyle = GetWindowLong(mdi.Handle, GWL_EXSTYLE);
ExStyle ^= WS_EX_CLIENTEDGE;
SetWindowLong(mdi.Handle, GWL_EXSTYLE, ExStyle);
SetWindowPos(mdi.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE |
SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
}