Im having problem with the newest button control added when i clicked on the button to move it. It jerks violently. The previous ones are alright. Can anyone assist with this problem?
Public Class Form1
Dim dragging As Boolean, startX, startY As Long
WithEvents x As Button
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Static idx As Long
x = New Button
x.Location = e.Location
x.Text = idx
idx += 1
Me.Controls.Add(x)
AddHandler x.MouseMove, AddressOf lblseat_MouseMove
AddHandler x.MouseDown, AddressOf lblseat_MouseDown
AddHandler x.MouseUp, AddressOf lblseat_MouseUp
End Sub
Private Sub lblseat_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseDown
Dim _x As Button = sender
Label1.Text = "<" & _x.Text
Label1.Refresh()
dragging = True
startX = e.X
startY = e.Y
End Sub
Private Sub lblseat_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseMove
Dim _x As Button = sender
If dragging = True Then
_x.Left = (_x.Left + e.X) - startX
_x.Top = (_x.Top + e.Y) - startY
End If
End Sub
Private Sub lblseat_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseUp
Dim _x As Button = sender
Label1.Text = ">" & _x.Text
Label1.Refresh()
dragging = False
End Sub
End Class
Public Class Form1
Dim dragging As Boolean, startX, startY As Long
WithEvents x As Button
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
Static idx As Long
x = New Button
x.Location = e.Location
x.Text = idx
idx += 1
Me.Controls.Add(x)
AddHandler x.MouseMove, AddressOf lblseat_MouseMove
AddHandler x.MouseDown, AddressOf lblseat_MouseDown
AddHandler x.MouseUp, AddressOf lblseat_MouseUp
End Sub
Private Sub lblseat_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseDown
Dim _x As Button = sender
Label1.Text = "<" & _x.Text
Label1.Refresh()
dragging = True
startX = e.X
startY = e.Y
End Sub
Private Sub lblseat_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseMove
Dim _x As Button = sender
If dragging = True Then
_x.Left = (_x.Left + e.X) - startX
_x.Top = (_x.Top + e.Y) - startY
End If
End Sub
Private Sub lblseat_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles x.MouseUp
Dim _x As Button = sender
Label1.Text = ">" & _x.Text
Label1.Refresh()
dragging = False
End Sub
End Class