2013-02-10 43 views
1

我正在使用C#爲應用程序的「全屏模式」使用無邊框窗體和最大化方法。 這是完美的,當我使表單無邊界,而它沒有最大化 - 你可以在屏幕上看到的是窗體,任務欄被覆蓋..但是,如果我手動最大化表單(用戶交互),然後嘗試使它無邊框&最大化,任務欄繪製在窗體上(因爲我沒有使用WorkingArea,窗體上的控件的一部分被隱藏,這是不顯示任務欄的預期行爲)。 我嘗試將表單的屬性TopMost設置爲true,但這似乎沒有任何效果。最大化無邊界窗體僅在從正常尺寸最大化時覆蓋任務欄

有沒有什麼辦法可以重寫這個來覆蓋任務欄?

if (this.FormBorderStyle != System.Windows.Forms.FormBorderStyle.None) 
    {   
    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
    } 
    else 
    { 
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; 
    } 
    if (this.WindowState != FormWindowState.Maximized) 
    { 
    this.WindowState = FormWindowState.Maximized; 
    } 
    else 
    { 
     if (this.FormBorderStyle == System.Windows.Forms.FormBorderStyle.Sizable) this.WindowState=FormWindowState.Normal; 
    } 

回答

1

然而,如果我最大化手動形式(用戶交互)...

問題是您的窗口已經在內部標記爲處於最大化狀態。所以最大化它再次不會更改窗體的當前大小。這將使任務欄暴露。您需要先將其恢復到正常狀態,然後再恢復到最大化狀態。是的,閃爍了一下。

private void ToggleStateButton_Click(object sender, EventArgs e) { 
     if (this.FormBorderStyle == FormBorderStyle.None) { 
      this.FormBorderStyle = FormBorderStyle.Sizable; 
      this.WindowState = FormWindowState.Normal; 
     } 
     else { 
      this.FormBorderStyle = FormBorderStyle.None; 
      if (this.WindowState == FormWindowState.Maximized) this.WindowState = FormWindowState.Normal; 
      this.WindowState = FormWindowState.Maximized; 
     } 
    } 
0

不知道爲什麼發生這種情況,我應用的是假定他們可以把我所有的屏幕。雖然這可能會爲1024×768的顯示器是可以接受的,當該死的東西決定它擁有我的屏幕我的30" 顯示器被浪費。

所以我的消息,可能專注於確保所有控制都可見而不是專注使窗口最大化

您可以隨時檢測窗口大小的變化,然後覆蓋默認行爲,照顧您遇到的意外問題,但不是最大化和取得所有30「顯示,計算有多大窗口需要,並相應地設置大小。

我的2美分,這正是我的想法是值得;)

+1

約翰,正在開發的應用程序不是公共應用程序,生產環境預計將完全禁用任務欄;然而,爲了純粹的目的,我想驗證我的應用程序可以在啓用任務欄的情況下處理Windows。除此之外,這個特定的場景正在被用於使VMR9渲染器全屏。你會同意,當你沒有那個任務欄時,看一些視頻會更愉快。 – zaitsman 2013-02-10 01:14:51

0

你可以嘗試使用WINAPI SetWindowPos方法,像這樣:

public static class WinApi 
{ 
    [DllImport("user32.dll")] 
    [return: MarshalAs(UnmanagedType.Bool)] 
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, 
            int x, int y, int width, int height, 
            uint flags); 

    static readonly IntPtr HWND_TOPMOST = new IntPtr(-1); 
    const uint SWP_NOSIZE = 0x0001; 
    const uint SWP_NOMOVE = 0x0002; 
    const uint SWP_SHOWWINDOW = 0x0040; 

    public static void SetFormTopMost(Form form) 
    { 
     SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, 
        SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 
    } 
} 

在您的形式稱呼它:

WinApi.SetFormTopMost(this);