【问题标题】:Maximizing borderless form with multiple monitors c#使用多个监视器最大化无边界表单c#
【发布时间】:2016-07-24 04:03:51
【问题描述】:

我目前正在制作一个带有 Doubleclick 事件的无边框表单以最大化表单。但我意识到表单不会在其他两个屏幕上最大化,只有我的主要中间。 所以我的代码目前是:

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 台显示器。

请帮忙。

【问题讨论】:

    标签: c# monitor maximize multiple-monitors borderless


    【解决方案1】:

    您将其硬编码到主屏幕,即带有任务栏的屏幕。为了允许其他屏幕获取屏幕,表单当前正在对此进行调整。

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

    【讨论】:

    • 成功了,之前看过代码,但是不知道怎么放。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多