Instead of drawing the text in the Paint() event, we could create actual Label controls and add them to the PictureBox:
Public Class Form1
Public Const HTCAPTION As Integer = &H2
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Declare Auto Function ReleaseCapture Lib "user32.dll" () As Integer
Public Declare Ansi Function DragControl Lib "user32.dll" Alias "SendMessageA" (ByVal handle As IntPtr, Optional ByVal Message As Integer = WM_NCLBUTTONDOWN, Optional ByVal HitTest As Integer = HTCAPTION, Optional ByVal wParam As Integer = 0) As Integer
Private startPt As Point
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NewLabel("Some Thing", New Point(25, 100))
NewLabel("Another Thing", New Point(150, 100))
NewLabel("Thing One", New Point(250, 300))
End Sub
Private Sub NewLabel(ByVal txt As String, ByVal location As Point)
Dim lbl As New Label
lbl.Text = txt
lbl.Location = location
lbl.BackColor = Color.Transparent
AddHandler lbl.MouseDown, AddressOf lbl_MouseDown
AddHandler lbl.MouseMove, AddressOf lbl_MouseMove
Me.Controls.Add(lbl)
lbl.Parent = PictureBox1
lbl.BringToFront()
End Sub
Private Sub lbl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
startPt = New Point(e.X, e.Y)
End If
End Sub
Private Sub lbl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim lbl As Label = CType(sender, Label)
lbl.Location = New Point(lbl.Location.X + (e.X - startPt.X), lbl.Location.Y + (e.Y - startPt.Y))
End If
End Sub
End Class
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42:





by: DeathracePosted on 2009-06-29 at 08:19:10ID: 24736975
Hi, /KB/cpp/vb netdragdro p.aspx
You said text, which control label or textbox you are using. Right now i can suggest one link as per my understanding. Check the below one.
http://www.codeproject.com