1

フォームを右の次のウィンドウに移動する方法を知っている人はいますか (または、現在のモニターが最後のウィンドウの場合は循環します)、最大化しますか? 私は遊んでいて、フォームが「通常」のウィンドウ状態にある場合にフォームを移動するコードをいくつか書きました(独学なので、親切にしてください)が、最大化部分で立ち往生しています。私は 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) を使用しています。

4

1 に答える 1