Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2012 DragDrop Dynamic Labels (on a Picbox)

$
0
0
I cant seem to get this working...
I have a picture box (with a map image)

Right click it - pick add plane from the context menu lets you type a name into an input box and poof! a new label appears with that name on it.

I would like to now be able to drag/drop the label to other places in the picture box
(in case it matters, i also need to be able to click it - to view detail - and right click it to pick from another menu BUT, i could use right btn to move if needed)

I mousedown.. and i get the no drag symbol... and nothing happens

adds label
Code:

Private Sub AddPlane(Serial As String)
        Dim LBL As New Label
        LBL.Text = Trim(Serial)
        LBL.BackColor = Color.WhiteSmoke
        LBL.BorderStyle = BorderStyle.FixedSingle
        LBL.Top = MP.Y
        LBL.Left = MP.X
        LBL.Font = New Font(New FontFamily("Microsoft Sans Serif"), 11, FontStyle.Bold, GraphicsUnit.Point)
        LBL.ForeColor = Color.Crimson
        LBL.AutoSize = True
        LBL.Visible = True
        LBL.ContextMenuStrip = cms_plane
        LBL.AllowDrop = True
        pb_Map.Controls.Add(LBL)

        AddHandler LBL.Click, AddressOf PLANE_CLICK
        AddHandler LBL.MouseDown, AddressOf PLANE_MOUSEDOWN
        AddHandler LBL.DragEnter, AddressOf PLANE_DRAGENTER
        AddHandler LBL.DragDrop, AddressOf PLANE_DRAGDROP
    End Sub

dragdrop code i have found "out there"
Code:

Private Sub PLANE_MOUSEDOWN(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        If Button.MouseButtons <> Windows.Forms.MouseButtons.Left Then Exit Sub
        Dim LBL As Label = DirectCast(sender, Label)
        LBL.DoDragDrop(LBL.Text, DragDropEffects.Copy Or DragDropEffects.Move)
    End Sub

    Private Sub PLANE_DRAGENTER(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effect = DragDropEffects.Copy
        Else
            e.Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub PLANE_DRAGDROP(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        Dim LBL As Label = DirectCast(sender, Label)
        LBL.Text = e.Data.GetData(DataFormats.Text).ToString
    End Sub


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>