Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each child As Control In Me.FlowLayoutPanel1.Controls
AddHandler child.MouseDown, AddressOf childs_MouseDown
Next
End Sub
Private dragcursor As Cursor, dragtype As Type
Private Sub childs_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If Me.ReorderCheckBox.Checked Then
Dim source As Control = CType(sender, Control)
Using bmp As New Bitmap(source.Width, source.Height)
source.DrawToBitmap(bmp, New Rectangle(Point.Empty, source.Size))
Me.dragcursor = New Cursor(bmp.GetHicon)
End Using
Me.dragtype = source.GetType
Me.FlowLayoutPanel1.DoDragDrop(source, DragDropEffects.Move)
Me.dragcursor.Dispose()
End If
End Sub
Private Sub FlowLayoutPanel1_GiveFeedback(ByVal sender As Object, ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles FlowLayoutPanel1.GiveFeedback
e.UseDefaultCursors = False
Cursor.Current = Me.dragcursor
End Sub
Private Sub FlowLayoutPanel1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FlowLayoutPanel1.DragEnter
If e.AllowedEffect = DragDropEffects.Move AndAlso e.Data.GetDataPresent(dragtype) Then
e.Effect = DragDropEffects.Move
End If
End Sub
Private Sub FlowLayoutPanel1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FlowLayoutPanel1.DragDrop
Dim source As Control = CType(e.Data.GetData(dragtype), Control)
Dim target As Control = Me.FlowLayoutPanel1.GetChildAtPoint(Me.FlowLayoutPanel1.PointToClient(New Point(e.X, e.Y)))
If target IsNot Nothing Then
Dim ix As Integer = Me.FlowLayoutPanel1.Controls.GetChildIndex(target)
Me.FlowLayoutPanel1.Controls.SetChildIndex(source, ix)
End If
End Sub