我需要拖动表单上的任何标签。
我正在使用此代码,问题是它只移动了 1 个标签label1
,我可以复制粘贴几次并且它可以工作,但我正在使用代码向表单添加新标签,并且该代码看不到它们。
如何单击并拖动表单上的任何标签?
Public Class Form1
Dim lbl As Label
Dim Off As Point
Private Sub obj1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles label1.MouseDown
Off.X = MousePosition.X - sender.Left
Off.Y = MousePosition.Y - sender.Top
End Sub
Private Sub obj1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles label1.MouseMove
If e.Button = MouseButtons.Left Then
sender.Left = MousePosition.X - Off.X
sender.Top = MousePosition.Y - Off.Y
End If
End Sub
End Class