In the following code ,i can drag an item in form.but it is same for all node.i want to specify an node & according to that picturebox will generate.i used "item.text" property in itemdrag event but it's note working.
Public Class Form1
Dim pic As New PictureBox
Public drag As Boolean = False
Public mousex, mousey As Integer
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Dim pic As New PictureBox
Dim rand As New Random
Randomize(System.DateTime.Now.Millisecond)
Threading.Thread.Sleep(10)
pic.Location = New Point((500 * Rnd()), (500 * Rnd()))
pic.BackColor = Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))
Me.Controls.Add(pic)
AddHandler pic.MouseDown, AddressOf pic_MouseDown
AddHandler pic.MouseMove, AddressOf pic_Mousemove
AddHandler pic.MouseUp, AddressOf pic_Mouseup
End Sub
Private Sub Form1_DragEnter1(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent("System.Windows.Forms.TreeNode", True) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
TreeView1.AllowDrop = False
End Sub
Private Sub TreeView1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TreeView1.DragOver
e.Effect = DragDropEffects.Link
End Sub
Private Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag
DoDragDrop(e.Item, DragDropEffects.Copy)
End Sub
Private Sub pic_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.Cursor = Cursors.Hand
drag = True
mousex = -e.X
mousey = -e.Y
Dim left As Integer = Me.PointToClient(MousePosition).X - sender.location.x
Dim right As Integer = Me.PointToClient(MousePosition).Y - sender.location.y
Dim width As Integer = Me.ClientSize.Width - (sender.width - left)
Dim height As Integer = Me.ClientSize.Height - (sender.width - right)
Windows.Forms.Cursor.Clip = Me.RectangleToScreen(New Rectangle(left, right, width, height))
sender.invalidate()
End If
End Sub
Private Sub pic_Mousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If drag Then
Dim mposition As New Point()
mposition = Me.PointToClient(MousePosition)
mposition.Offset(mousex, mousey)
sender.location = mposition
End If
End Sub
Private Sub pic_Mouseup(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
drag = False
Windows.Forms.Cursor.Clip = Nothing
Me.Cursor = Cursors.Arrow
sender.invalidate()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Me.Enabled = False
End Sub
End Class
[edit]Code block added - OriginalGriff[/edit]