hallo,
so ist es möglich controls auf der form zu ziehen (wenn du das auch gemeint hast)
' BEISPIEL MIT EINEM BUTTON
Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
If e.Button = MouseButtons.Left Then
CType(sender, Button).Location = Me.PointToClient(Me.MousePosition)
End If
End Sub DRAG'N'DROP
benötigt wird eine Form mit zwei ListBoxen (listBox1 / listBox2)
DIe ListBox(en)-Eigenschaft AllowDrop auf True setzen!
Private Sub ListBoxes_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown, _
ListBox2.MouseDown
Dim lb As ListBox
If e.Button = MouseButtons.Left Then
lb = CType(sender, ListBox)
If lb.SelectedItems.Count > 0 Then
lb.DoDragDrop(lb, DragDropEffects.Move Or DragDropEffects.Copy)
End If
End If
End Sub
Private Sub ListBoxes_DragEnterOver(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles ListBox1.DragEnter, _
ListBox2.DragEnter, ListBox1.DragOver, ListBox2.DragOver
If e.Data.GetDataPresent(GetType(ListBox)) Then
If (Me.ModifierKeys And Keys.Control) = Keys.Control Then
e.Effect = DragDropEffects.Copy
ElseIf Not (sender Is e.Data.GetData(GetType(ListBox))) Then
e.Effect = DragDropEffects.Move
End If
End If
End Sub
Private Sub ListBoxes_DragDrop(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DragEventArgs) Handles ListBox1.DragDrop, _
ListBox2.DragDrop
Dim i, n As Integer
Dim lbSource, lbDestination As ListBox
Dim copyItems As Boolean = _
(ModifierKeys And Keys.Control) = Keys.Control
If e.Data.GetDataPresent(GetType(ListBox)) Then
lbDestination = CType(sender, ListBox)
lbSource = CType(e.Data.GetData(GetType(ListBox)), ListBox)
If lbSource.SelectedIndices.Count > 0 Then
For i = lbSource.SelectedIndices.Count - 1 To 0 Step -1
n = lbSource.SelectedIndices(i)
lbDestination.Items.Add(lbSource.Items(n))
If Not copyItems Then
lbSource.Items.Remove(lbSource.Items(n))
End If
Next
End If
End If
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
For a As Integer = 0 To 10
Me.ListBox1.Items.Add(a)
Me.ListBox2.Items.Add(a ^ 2)
Next
End Sub gruss steve |