C# 使用多个监视器最大化无边界形式#

C# 使用多个监视器最大化无边界形式#,c#,monitor,maximize,multiple-monitors,borderless,C#,Monitor,Maximize,Multiple Monitors,Borderless,我目前正在制作一个无边界表单,通过双击事件最大化表单。但我意识到表单不会在另外两个屏幕上最大化,只有我的主屏幕。 所以我的代码是: private void Form1_DoubleClick(object sender, EventArgs e) { if ((this.Height == Screen.PrimaryScreen.WorkingArea.Height) && (this.Width == Screen.PrimaryScreen.WorkingArea

我目前正在制作一个无边界表单,通过双击事件最大化表单。但我意识到表单不会在另外两个屏幕上最大化,只有我的主屏幕。 所以我的代码是:

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;
    }  
}
它可能看起来很奇怪,但我用它来不覆盖任务栏。 我需要一个这样的代码将它停靠在一边,并使用它来计算表单应该在哪里。看起来像这样: 当我点击这9个按钮中的一个时,它会将屏幕停靠在屏幕的不同位置。在角落,一半的屏幕或在中间。

我尝试使用一个代码,表单将检测它在哪个屏幕上,并再次使用该代码来最大化该屏幕上的表单,但我得到了一堆红线,最终没有起作用

我有3台显示器


请提供帮助。

您将其硬编码到主屏幕,即带有任务栏的屏幕。为了允许其他屏幕获得该屏幕,表单当前处于调整状态

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;
    }  
}

它工作了,我以前看过代码,但我不知道如何把它放进去。谢谢