VB.net 无边框窗体在任务栏上最大化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28241326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:45:15  来源:igfitidea点击:

VB.net Borderless Form Maximize over Taskbar

vb.netmaximizetaskbarmaximize-window

提问by Jarron

When I maximize my borderless form, the form covers the entire screen including the taskbar, which I don't want it to do. I'm finding it very difficult to find a solution to my problem on the net, all I've come up with is the below code, which displays the taskbar for a short time, but then disappears and the form still takes up the entire screen.

当我最大化我的无边框表单时,该表单覆盖了整个屏幕,包括任务栏,我不希望它这样做。我发现很难在网上找到我的问题的解决方案,我想出的只是下面的代码,它在短时间内显示任务栏,但随后消失了,表单仍然占据了整个屏幕。

Private Sub TableLayoutPanel1_DoubleClick(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.DoubleClick
    If e.Location.Y < 30 Then
        Me.WindowState = FormWindowState.Maximized
        Me.ControlBox = True
    End If
End Sub

I'm starting to think the only way to solve my problem is to find the screen size height minus the taskbar height to get the form height, but I'm hoping there might be a simpler answer.

我开始认为解决我的问题的唯一方法是找到屏幕尺寸高度减去任务栏高度以获得表单高度,但我希望可能有一个更简单的答案。

回答by Hans Passant

Use the form's Load event to set its maximum size, like this:

使用窗体的 Load 事件设置其最大大小,如下所示:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.MaximumSize = Screen.FromRectangle(Me.Bounds).WorkingArea.Size
End Sub

Maximizing it now restricts the size to the monitor's working area, which is the monitor size minus the taskbars.

现在最大化它会限制显示器工作区域的大小,即显示器大小减去任务栏。

回答by Idle_Mind

Use the "working area" of the screen:

使用屏幕的“工作区”:

    Me.Bounds = Screen.GetWorkingArea(Me)

回答by Simonetos The Greek

You should better do this:

你最好这样做:

Me.MaximumSize = Screen.FromControl(Me).WorkingArea.Size

Because some users use multiple monitors. So if you use Hans Passant's way, when user maximize application to secondary monitor, application will get primary's monitor working area size and will look awful!!!

因为有些用户使用多台显示器。因此,如果您使用 Hans Passant 的方式,当用户将应用程序最大化到辅助监视器时,应用程序将获得主监视器的工作区域大小并且看起来很糟糕!!!

回答by Saan

I think this is a better way to solve your problem

我认为这是解决您问题的更好方法

  Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Normal
        Me.StartPosition = FormStartPosition.Manual
        With Screen.PrimaryScreen.WorkingArea
            Me.SetBounds(.Left, .Top, .Width, .Height)
        End With
    End Sub