2016-07-24 99 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

相关问题