-3

This is Visual Basic 6.0 code.

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

Can anyone translate it to Visual Basic.Net, please?

1 Answers1

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
OneFineDay
  • 9,004
  • 3
  • 26
  • 37