【发布时间】:2014-12-08 22:43:43
【问题描述】:
有谁知道如何将表单移动到右侧的下一个窗口(或者如果当前监视器是最后一个则循环)并最大化它?我一直在玩并编写了一些代码(自学,所以请善待),如果它处于“正常”窗口状态,它会移动表单,但我被困在最大化部分。我原以为 WindowState = Maximized 会这样做,但在表单上设置会导致移动功能没有响应。
下面是我目前的代码:
Module Monitor
Public totalMonitors As Integer = System.Windows.Forms.Screen.AllScreens.Count
Private xPositionForMonitors As New Dictionary(Of Integer, Integer)
Private yPositionForMonitors As New Dictionary(Of Integer, Integer)
Private currentMonitorIndex As Integer
Private newMonitorIndex As Integer
Public Sub buildMonitorArray()
For m As Integer = 0 To (totalMonitors - 1)
xPositionForMonitors.Add(m, System.Windows.Forms.Screen.AllScreens(m).WorkingArea.Location.X)
yPositionForMonitors.Add(m, System.Windows.Forms.Screen.AllScreens(m).WorkingArea.Location.Y)
Next
End Sub
Public Sub moveToNextMonitor(targWindow As Form)
identifyCurrentMonitor(targWindow)
targWindow.SetDesktopLocation(xPositionForMonitors(newMonitorIndex) + 1, 0)
End Sub
Private Sub identifyCurrentMonitor(targWindow As Form)
For c As Integer = 0 To (totalMonitors - 1)
If targWindow.Location.X + 10 > xPositionForMonitors(c) Then
currentMonitorIndex = c
End If
Next
newMonitorIndex = currentMonitorIndex + 1
If newMonitorIndex = totalMonitors Then newMonitorIndex = 0
End Sub
End Module
目前,我在表单加载时调用 buildMonitorArray 函数,然后在表单上使用 moveToNextMonitor(Me)。
【问题讨论】:
-
在 moveToNextMonitor 之后是否将 WindowState 设置为 FormWindowState.Maximized?
-
在 Windows 7/8 中,只需 Windows 键 + Shift 键 + 右箭头移动到右侧的显示器,Windows 键 + 上箭头最大化。
标签: vb.net forms windowstate