最大化表单,但不覆盖任务栏



当我点击按钮最大化我的表单时,它覆盖了整个屏幕,包括任务栏。我设法找到了一个解决方案,它的工作原理,我使用我的代码在形式加载事件,但我不能返回到正常状态的形式。

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

最新更新