Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 全屏模式,但不';不要遮住任务栏_C#_.net_Winforms - Fatal编程技术网

C# 全屏模式,但不';不要遮住任务栏

C# 全屏模式,但不';不要遮住任务栏,c#,.net,winforms,C#,.net,Winforms,我有一个WinForms应用程序,当我登录时它被设置为全屏模式 我的问题是它也覆盖了Windows任务栏。我不希望我的应用程序覆盖任务栏 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load( object sender, EventArgs e ) { FormBorder

我有一个WinForms应用程序,当我登录时它被设置为全屏模式

我的问题是它也覆盖了Windows任务栏。我不希望我的应用程序覆盖任务栏

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e )
    {
        FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        Left = Top = 0;
        Width = Screen.PrimaryScreen.WorkingArea.Width;
        Height = Screen.PrimaryScreen.WorkingArea.Height;
    }
}

如何做到这一点?

如果最大化不是您想要的,那么您需要自己通过检查任务栏的位置和大小来计算窗口大小:


这可能就是你想要的。它在不隐藏任务栏的情况下创建“最大化”窗口

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e )
    {
        FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        Left = Top = 0;
        Width = Screen.PrimaryScreen.WorkingArea.Width;
        Height = Screen.PrimaryScreen.WorkingArea.Height;
    }
}

如果要使用
WindowState=Maximized
,您应该首先指出由
MaximizedBounds
属性最大化的窗体的大小限制

例如:

MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
WindowState = FormWindowState.Maximized;
您在哪里将表单的大小限制为工作区(即您的桌面区域)​​显示器

我有答案:

我在描述中遗漏了一件事——我关掉了最大化按钮。当我测试重新打开该属性时,任务栏再次出现。显然,它假设如果你不想要一个最大化按钮,你正在创建一个亭式的应用程序,你不想让你的用户看到除了应用程序屏幕以外的任何东西。这不完全是我所期望的,但我想是有效的

我遇到了这个问题,在杰夫的帮助下解决了。首先,将WindowsState设置为最大化。但不要禁用MaximizeBox。然后,如果希望禁用MaximizeBox,则应以编程方式执行此操作:

private void frmMain_Load(object sender, EventArgs e)
{
    this.MaximizeBox = false;
}

尝试不使用
FormBorderStyle=System.Windows.Forms.FormBorderStyle.None和注释行,如:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load( object sender, EventArgs e )
    {
        // FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        Left = Top = 0;
        Width = Screen.PrimaryScreen.WorkingArea.Width;
        Height = Screen.PrimaryScreen.WorkingArea.Height;
    }
}

我这样做的方式是通过以下代码:

this.MaximizedBounds = Screen.FromHandle(this.Handle).WorkingArea;
this.WindowState = FormWindowState.Maximized;

如果有多个屏幕,则必须重置MaximizedBounds的位置:

Rectangle rect = Screen.FromHandle(this.Handle).WorkingArea;
rect.Location = new Point(0, 0);
this.MaximizedBounds = rect;
this.WindowState = FormWindowState.Maximized;

我不擅长解释,但这是我用来最大化或全屏显示winforms的代码,它不会覆盖任务栏。希望能有帮助^^

private void Form_Load(object sender, EventArgs e)
{
    this.Height = Screen.PrimaryScreen.WorkingArea.Height;
    this.Width = Screen.PrimaryScreen.WorkingArea.Width;
    this.Location = Screen.PrimaryScreen.WorkingArea.Location;
}
对于单显示器来说是很好的,但是如果您在除最左边的屏幕之外的任何屏幕上尝试它,它只会使窗体消失。我使用了下面的代码

var workingArea = Screen.FromHandle(Handle).WorkingArea;
MaximizedBounds =  new Rectangle(0, 0, workingArea.Width, workingArea.Height);
WindowState = FormWindowState.Maximized;

唯一的区别是我将顶部和左侧的值覆盖为0,0,因为它们在其他屏幕上会有所不同。

这就是全屏的定义。也许您希望将其设置为“最大化”相反?@Evil:你应该用你的问题来回答这个问题。@E:我把它设为这个。windowstate=maximized…我认为这应该是认可的答案,因为上面提供的解决方案不允许正常的Windows状态更改行为。简单地说,公认的答案基本上是stackoverflow rep hunt;想出一个一年级学生能想出的不完美的解决方案。这是OP要求的,这个!关于这个代码唯一答案的一些解释可能是有益的!我这样解析:Size=Screen.FromHandle(Handle.WorkingArea.Size);位置=屏幕.FromHandle(Handle).WorkingArea.Location;