2016-07-24 101 views
-1

我目前正在用Doubleclick事件製作無邊界窗體以最大化窗體。但是我意識到,表格不會在其他兩個屏幕上最大化,只有我的主要中間。 所以我的代碼目前是:使用多個顯示器c最大化無邊界窗體#

private void Form1_DoubleClick(object sender, EventArgs e) 
{ 
    if ((this.Height == Screen.PrimaryScreen.WorkingArea.Height) && (this.Width == Screen.PrimaryScreen.WorkingArea.Width)) 
    { 
     this.Width = 534; 
     this.Height = 600; 
     CenterToScreen(); 
    } 
    else 
    { 
     this.Height = Screen.PrimaryScreen.WorkingArea.Height; 
     this.Width = Screen.PrimaryScreen.WorkingArea.Width; 
     this.Location = Screen.PrimaryScreen.WorkingArea.Location; 
    } 
} 

它看起來怪異,但我用它不包括任務欄。 我需要這樣的代碼將其停靠在一邊,並用它來計算窗體的位置。看起來像這樣:half right screen dock 當我點擊這9個按鈕中的一個時,它會將屏幕停靠在屏幕的不同位置。在角落,一半的屏幕或中間。

我嘗試使用代碼,其中窗體會檢測到它在哪個屏幕上,並再次使用它來最大化該屏幕上的窗體,但我得到了一堆紅線,並且它最終沒有工作。

我有3臺顯示器。

請幫忙。

回答

0

您將其硬編碼爲主屏幕,即具有任務欄的屏幕。爲了讓其他屏幕獲得屏幕,表單目前正在對此進行調整。

private void Form1_DoubleClick(object sender, EventArgs e) 
{ 
    if ((this.Height == Screen.FromControl(this).WorkingArea.Height) && (this.Width == Screen.FromControl(this).WorkingArea.Width)) 
    { 
     this.Width = 534; 
     this.Height = 600; 
     CenterToScreen(); 
    } 
    else 
    { 
     this.Height = Screen.FromControl(this).WorkingArea.Height; 
     this.Width = Screen.FromControl(this).WorkingArea.Width; 
     this.Location = Screen.FromControl(this).WorkingArea.Location; 
    } 
} 
+0

它工作,我以前見過代碼,但我不知道如何把它放在。謝謝 – KrisPus

相關問題