2010-07-28 41 views
0

我做了一個自定義窗口爲我的應用程序和我寫了一些代碼,如果用戶單擊我的自定義最大化按鈕:最大化自定義窗口,包括任務欄

private void MaxThis(object sender, System.Windows.RoutedEventArgs e) 
    { if (WindowState == WindowState.Maximized){ 
     WindowState = WindowState.Normal;} 

    else { 
    this.Top = 0; 
    this.Left = 0; 
    this.MaxWidth = System.Windows.SystemParameters.WorkArea.Width; 
    this.MaxHeight = System.Windows.SystemParameters.WorkArea.Height; 
    this.WindowState = WindowState.Maximized; 
    } 
    } 

的恢復到正常狀態正常工作。但是,當我想要最大化時,它會使屏幕右側和底部的邊距保持最小。再次點擊最大化以某種方式修復此問題。如何解決這個問題,以便在第一次點擊時最大化?

+0

你試過在每個連續的調試最大化/標準化點擊並查看實際設置的值?也許你沒有考慮到窗口邊界,邊距等事情。我猜這是WPF? – SirDemon 2010-07-28 14:01:58

+0

你猜對了:)事情是我沒有任何邊框或邊距設置,它都是零... – internetmw 2010-07-28 14:03:18

+0

關於如何調試和獲取屏幕值的任何提示? – internetmw 2010-07-28 14:33:41

回答

0

嘗試使用剛剛

this.WindowState = WindowState.Maximized; 

也許碼,搞亂Windows API的行動之前進入。


對不起,我的錯。 然後你應該使用Windows API來提高最大化事件。 試試這個代碼:

[DllImport("user32.dll")] 
public static extern int SendMessage(
    int hWnd,  // handle to destination window 
    uint Msg,  // message 
    long wParam, // first message parameter 
    long lParam // second message parameter 
); 
public const int WM_SIZE = 0x0005; 
public const int SIZE_MAXIMIZED = 2; 

而且在點擊事件:

SendMessage(this.Handle, WM_SIZE, SIZE_MAXIMIZED, 0); 
+2

不能使用這個,因爲那麼窗口也會覆蓋我的任務欄... – internetmw 2010-07-28 14:02:33

2

帶走你在XAML爲您的窗口中設置的高度和寬度屬性

相關問題