这是Visual Basic 6.0代码。
Dim cx, cy, dx, dy As Single
Dim bDrag As Boolean
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
bDrag = True : dx = X : dy = Y : cx = Me.Left : cy = Me.Top
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If bDrag Then
cx = cx + X - dx : cy = cy + Y - dy
Me.Move(cx, cy)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
bDrag = False
End Sub
有人可以将它翻译成Visual Basic.Net吗?
答案 0 :(得分:2)
Dim cx, cy, dx, dy As Single
Dim bDrag As Boolean
Private Sub Form_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
bDrag = True : dx = e.X : dy = e.Y : cx = Me.Left : cy = Me.Top
End Sub
Private Sub Form_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If bDrag Then
cx = cx + e.X - dx : cy = cy + e.Y - dy
Me.Location = New Point(cx, cy)
End If
End Sub
Private Sub Form_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
bDrag = False
End Sub