1

このコードを使用して、カスタム フォームを最大化および復元しました。しかし、フォームが最大化されてもドラッグ可能なままなので、タイマーを使用してフォームをドラッグします。

Private Sub btnMaximize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMaximize.Click, lblTitle.MouseDoubleClick
    Dim maximizeHeight As Integer = Screen.PrimaryScreen.WorkingArea.Height
    Dim maximizeWidth As Integer = Screen.PrimaryScreen.WorkingArea.Width
    Dim maximizeLocation As Point = New Point(0, 0)
    Dim fullscreen As Boolean = False

    If Me.Height = maximizeHeight Or Me.Width = maximizeWidth Or Me.Location = maximizeLocation Then
        fullscreen = True
    Else
        fullscreen = False
    End If

    If fullscreen = True Then
        Me.Size = New Size(1000, 500)
        Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) / 2
        Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) / 2
    ElseIf fullscreen = False Then
        Me.Location = New Point(0, 0)
        Me.Size = New Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
    End If
End Sub

Private Sub pnlBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblTitle.MouseDown
    MoveTmr.Start()
    refpositions()
End Sub

Private Sub MoveTmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MoveTmr.Tick
    Me.Location = oloc - ocur + System.Windows.Forms.Cursor.Position
    refpositions()
End Sub

Private Sub pnlBar_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblTitle.MouseUp
    MoveTmr.Stop()
    refpositions()
End Sub

Private Sub RszTmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles RszTmr.Tick
    Me.Size = appSize - curPos + Cursor.Position
    refpositions()
End Sub
4

3 に答える 3

1

作る:

Dim fullscreen As Boolean = False

クラス変数。

次に、変数に合わせてこのコードを編集します。

Private Sub Mover_Tick(sender As System.Object, e As System.EventArgs) Handles Mover.Tick
    If fullscreen = false Then
         Dim pt As New Point((Me.Location.X + (MousePosition.X - mPosX)), (Me.Location.Y + (MousePosition.Y - mPosY)))
         Me.Location = pt
         mPosX = MousePosition.X
         mPosY = MousePosition.Y
    End If
End Sub

編集:

これも実装します:

Private Sub Title_StartDrag(sender As System.Object, e As MouseEventArgs) Handles Title.MouseDown
    mPosX = MousePosition.X
    mPosY = MousePosition.Y
    If e.Button = Windows.Forms.MouseButtons.Left Then
        Mover.Start()
    End If
End Sub

Private Sub Title_StopDrag(sender As System.Object, e As MouseEventArgs) Handles Title.MouseUp
    Mover.Stop()
End Sub

また、 Me.WindowState = FormWindowState.Maximized と言って、もっと簡単にしたいかもしれません

于 2012-10-20T16:41:05.097 に答える