我同意馬特。設置「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