0

VB 形式で作成されたラベルをドラッグしたい。コードを使用してラベルを作成する場合、それは可能ですか?

例: 20 個のラベルがあり、それらはすべて異なる名前です。カーソルでクリックしたラベルをドラッグできるコードはありますか?そのコードを使用しましたが、以前に作成したラベルのみをドラッグしますが、コードを使用してラベルを作成する場合、それらをドラッグする方法はありますか:

1 つのラベルをドラッグするためのコード

編集ビューで追加された 1 つのラベルのみをクリックしてドラッグするコード

Private Sub obj1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)  'varocarbas
        ' Check if the mouse is down
        If Go = True Then
            ' Set the mouse position
            HoldLeft = (Control.MousePosition.X - Me.Left)
            HoldTop = (Control.MousePosition.Y - Me.Top)
            ' Find where the mouse was clicked ONE TIME
            If TopSet = False Then
                OffTop = HoldTop - sender.Top
                ' Once the position is held, flip the switch
                ' so that it doesn't keep trying to find the position
                TopSet = True
            End If
            If LeftSet = False Then
                OffLeft = HoldLeft - sender.Left
                ' Once the position is held, flip the switch
                ' so that it doesn't keep trying to find the position
                LeftSet = True
            End If
            ' Set the position of the object
            sender.Left = HoldLeft - OffLeft
            sender.Top = HoldTop - OffTop
        End If

    End Sub

フォームにラベルを作成するためのコード

Public Class Form1
    Dim counter As Integer = 1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        Dim lbl As New Label

        lbl.Name = "Label" & counter

        lbl.Size = New Size(80, 20)

        lbl.Location = New Point(80, counter * 22)

        lbl.Text = TextBox1.Text

        AddHandler lbl.MouseMove, AddressOf obj1_MouseMove 'varocarbas

        Me.Controls.Add(lbl)

        counter += 1

    End Sub

End Class

作成したラベルをドラッグしたい。それは可能ですか?

4

1 に答える 1