누구든지 양식을 오른쪽의 다음 창으로 이동 (또는 현재 모니터가 마지막 모니터 인 경우 순환)하고 최대화하는 방법을 알고 있습니까? 나는 "정상"윈도우 상태에있는 경우 폼을 이동하는 코드 (자신을 배웠으므로 친절 해지십시오)를 가지고 놀면서 작성했지만 최대화 부분에 갇혀 있습니다. 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)를 사용하고 있습니다.
이동하기 전에 WindowState를 Normal로 설정 한 다음 이동하면 원래 상태로 다시 설정해야합니다. 양식을 이동하기 전에 buildMonitorArray 메서드를 호출하는 것에 대해 걱정할 필요가 없도록 코드를 클래스로 변환했습니다. 메서드를 호출하려면 현재 클래스이므로 Monitor.moveToNextMonitor를 호출해야합니다. 여전히 모듈을 사용하고 싶다면 코드 변경 사항을 모듈로 이식 할 수 있으며 여전히 동일한 방식으로 작동합니다.
Public Class Monitor
Shared Sub New()
buildMonitorArray()
End Sub
Public Shared totalMonitors As Integer = System.Windows.Forms.Screen.AllScreens.Count
Private Shared xPositionForMonitors As New Dictionary(Of Integer, Integer)
Private Shared yPositionForMonitors As New Dictionary(Of Integer, Integer)
Public Shared 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 Shared Sub moveToNextMonitor(targWindow As Form)
Dim newMonitorIndex As Integer = identifyCurrentMonitor(targWindow)
Dim originalState = targWindow.WindowState
Try
If originalState <> FormWindowState.Normal Then
targWindow.WindowState = FormWindowState.Normal
End If
targWindow.SetDesktopLocation(xPositionForMonitors(newMonitorIndex) + 1, 0)
Finally
targWindow.WindowState = originalState
End Try
End Sub
Private Shared Function identifyCurrentMonitor(targWindow As Form) As Integer
Dim currentMonitorIndex As Integer
Dim newMonitorIndex As Integer
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
Return newMonitorIndex
End Function
End Class
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다