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 43 44 45 46 47 48 49
|
Public Class Form1
Private _movedButton As Button
Private Sub FlowLayoutPanel1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles FlowLayoutPanel1.DragEnter
If e.Data.GetDataPresent("System.Windows.Forms.Button") 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
If e.Data.GetDataPresent("System.Windows.Forms.Button") Then
Dim monCmd As Windows.Forms.Button = CType(e.Data.GetData("System.Windows.Forms.Button"), Button)
Me.FlowLayoutPanel1.Controls.Remove(_movedButton)
With monCmd
.Location = Me.PointToClient(New Point(e.X, e.Y))
.Visible = True
End With
Me.FlowLayoutPanel1.Controls.Add(monCmd)
End If
End Sub
Private Sub common_buttonMouseDownEvent(ByVal X As Integer, ByVal Y As Integer, ByVal mouseButton As Windows.Forms.MouseButtons)
If mouseButton = Windows.Forms.MouseButtons.Left Then
_movedButton = CType(Me.FlowLayoutPanel1.GetChildAtPoint(New Point(X, Y)), Button)
_movedButton.DoDragDrop(_movedButton, DragDropEffects.Move)
Me.Button1.DoDragDrop(_movedButton, DragDropEffects.Move)
End If
End Sub
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
common_buttonMouseDownEvent(e.X, e.Y, e.Button)
End Sub
Private Sub Button2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button2.MouseDown
common_buttonMouseDownEvent(e.X, e.Y, e.Button)
End Sub
' .
' .
' .
' Private Sub ButtonN_MouseDown(ByVal sender As Object, ByVal e As
' System.Windows.Forms.MouseEventArgs) Handles ButtonN.MouseDown
' common_buttonMouseDownEvent(e.X, e.Y, e.Button)
' End Sub
End Class |
Partager