最大化窗体但不覆盖任务栏
Maximize form but do not cover the taskbar
当我单击按钮最大化我的表单时,它覆盖了整个屏幕,包括任务栏。我设法找到了一个解决方案并且它有效,我在表单加载事件中使用了我的代码,但我无法 return 表单进入正常状态。
Private Sub frmDashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
End Sub
Private Sub btnMaximizeMin_Click(sender As Object, e As EventArgs) Handles btnMaxMin.Click
If Me.WindowState = FormWindowState.Normal Then
'maximize but dont cover taskbar
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
Else
Me.WindowState = FormWindowState.Normal
End If
End Sub
问题是您没有最大化表单。您特别不想最大化表单,因为它覆盖了 Windows 任务栏。您不能将 WindowState
“返回”设置为 Normal
,因为它已经处于该状态,因为它永远不会离开该状态。由您自己记住状态以及之前的边界,例如
Private isMaximised As Boolean = False
Private normalBounds As Rectangle
Private Sub MaximiseOrRestore()
isMaximised = Not isMaximised
If isMaximised Then
normalBounds = Bounds
Bounds = Screen.PrimaryScreen.WorkingArea
Else
Bounds = normalBounds
End If
End Sub
当我单击按钮最大化我的表单时,它覆盖了整个屏幕,包括任务栏。我设法找到了一个解决方案并且它有效,我在表单加载事件中使用了我的代码,但我无法 return 表单进入正常状态。
Private Sub frmDashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
End Sub
Private Sub btnMaximizeMin_Click(sender As Object, e As EventArgs) Handles btnMaxMin.Click
If Me.WindowState = FormWindowState.Normal Then
'maximize but dont cover taskbar
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
Else
Me.WindowState = FormWindowState.Normal
End If
End Sub
问题是您没有最大化表单。您特别不想最大化表单,因为它覆盖了 Windows 任务栏。您不能将 WindowState
“返回”设置为 Normal
,因为它已经处于该状态,因为它永远不会离开该状态。由您自己记住状态以及之前的边界,例如
Private isMaximised As Boolean = False
Private normalBounds As Rectangle
Private Sub MaximiseOrRestore()
isMaximised = Not isMaximised
If isMaximised Then
normalBounds = Bounds
Bounds = Screen.PrimaryScreen.WorkingArea
Else
Bounds = normalBounds
End If
End Sub