且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Windows窗体上拖放

更新时间:2023-11-22 17:36:34

尝试一下,我已经在两个事件中更改了代码,其余的实现是完整的.

give a try to this, I have changed code in two events rest of the implementation is intact.

 Private Sub TreeView1_ItemDrag(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemDragEventArgs) Handles TreeView1.ItemDrag
     If (CType(e.Item, TreeNode).Parent Is Nothing) Then
         Dim nodes As TreeNodeCollection = CType(e.Item, TreeNode).Nodes
         For Each node As TreeNode In nodes
             DoDragDrop(node, DragDropEffects.Copy)
         Next
     Else
         DoDragDrop(e.Item, DragDropEffects.Copy)
     End If
 End Sub


Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
     pic = New PictureBox    ' every time create a new pictureBox control
     With pic
         .Size = New Size(100, 100)
         .BackColor = Color.Black
         Me.Controls.Add(pic)
     End With

     AddHandler pic.MouseDown, AddressOf pic_MouseDown
     AddHandler pic.MouseMove, AddressOf pic_Mousemove
     AddHandler pic.MouseUp, AddressOf pic_Mouseup
 End Sub