Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
Me.PictureBox2.DoDragDrop(sender, DragDropEffects.Move)
End Sub
Private Sub GroupBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles GroupBox1.DragEnter
e.Effect = DragDropEffects.Move '拖放事件的目标所允许的动作
End Sub
Private Sub GroupBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles GroupBox1.DragDrop
Me.PictureBox1.Controls.Remove(Me.PictureBox2)
Me.GroupBox1.Controls.Add(Me.PictureBox2)
Me.PictureBox2.Left = 0
Me.PictureBox2.Top = 10
MessageBox.Show("dfgdf")
End Sub
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.GroupBox1.AllowDrop = True
Me.PictureBox1.AllowDrop = True
End Sub
这篇博客介绍了如何在Windows Forms应用中实现控件的拖放操作,特别是从一个容器控件到另一个容器控件的移动。通过处理MouseDown、DragEnter、DragDrop事件,可以实现PictureBox控件在GroupBox之间的移动,并在DragDrop事件中更新控件的位置。
279

被折叠的 条评论
为什么被折叠?



