我同意马特。设置“MaximizedBounds”不是一个好主意。 正如在Event when a window gets maximized/un-maximized中所写,我会覆盖WndProc方法。在那里你可以自己处理来自窗口的不同的接收命令。
要做的主要事情是编写自己的代码“SC_MAXIMIZE”-windowcommand(如上面引用的文章中所写)。您可以手动设置表单的大小,例如在这种情况下,表单不会真正达到最大化。实际上它仍然在正常的WindowState中。为了防止用户改变这个状态,你需要“捕捉”一些其他的窗口命令。
重写的WndProc方法可能是这样的:
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x0112) // WM_SYSCOMMAND
{
if(m.WParam == new IntPtr(0xF012)) //TITLE_CLICK_ONCE
{
// catch, this command can occur, when form starts to move
}
if(m.WParam == new IntPtr(0xF001) // RESIZE_ON_EDGE
|| m.WParam == new IntPtr(0xF002)
|| m.WParam == new IntPtr(0xF003)
|| m.WParam == new IntPtr(0xF004)
|| m.WParam == new IntPtr(0xF005)
|| m.WParam == new IntPtr(0xF006)
|| m.WParam == new IntPtr(0xF007)
|| m.WParam == new IntPtr(0xF008))
{
// catch the resizing
}
if(m.WParam == new IntPtr(0xF032)) // SECOND_CLICK_ON_TITLEBAR
{
// catch. causes a maximization (or resuming to normal window-mode)
}
if(m.WParam == new IntPtr(0xF030)) //SC_MAXIMIZE
{
// the actual point, where to enter your code
// this command occurs, when the "Maximize"-button is pressed
}
}
// maybe abort calling of the base-method at specified window-commands,
// when you want to make your own code by simply "return;"
base.WndProc(ref m);
}
Gk,你猜这是要走的路。 – Stimpatch 2010-02-03 15:13:37