-1

我正在学习 vstudio 2012,我正在尝试使用“borderstyle = none”制作可移动的表单,但我做不到。

我在 Google 中找到的所有信息都讨论了有关此问题的 vb4 5 和 6,版本对我来说太早了,我无法使用它们(我不知道如何使用)。

我的声明非常简单,我只需要通过单击应用程序(表单上的任何位置)使窗口可移动:

Public Class Form1

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label2.Text = "X: " & MousePosition.X
        Label3.Text = "Y: " & MousePosition.Y

    End Sub

    Sub Form1_KeyPress(ByVal sender As Object, _
      ByVal e As KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar >= ChrW(3) Then
            Clipboard.SetDataObject(Label2.Text & " " & Label3.Text)
        End If
    End Sub

End Class

请问有什么帮助吗?谢谢你阅读

4

1 回答 1

0

我已经解决了,谢谢。

Private ArrastrarForm As Boolean
Private PosicionMouseHeader As Point
Private tmpPoint As Point


Private Sub Form1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left Then
        ArrastrarForm = True
        PosicionMouseHeader = e.Location
    End If
End Sub

Private Sub Form1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    If ArrastrarForm Then
        tmpPoint = Me.Location + e.Location - PosicionMouseHeader
        Me.Location = tmpPoint
    End If
End Sub

Private Sub Form1_MouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
    If e.Button = Windows.Forms.MouseButtons.Left Then
        ArrastrarForm = False
    End If
End Sub

再见!

于 2012-11-07T16:51:11.133 回答