![]() |
Tipp 0127
|
Datei-Drag & Drop in eine ListBox
|
 |
|
Autor/Einsender: Datum: |
|
Michael Werner 28.07.2006 |
|
Entwicklungsumgebung: |
|
VB.Net 2003 |
Framework: |
|
1.1 |
|
|
In diesem Beispiel wird Drag & Drop zum Füllen eines ListBox-Steuerelements mit einer Liste von Dateien verwendet, die aus dem Windows-Explorer
gezogen wurden. Das Drag & Drop für ein Steuerelement wird aktiviert durch das Setzen der AllowDrop-Eigenschaft auf True.
Im DragEnter-Ereignis wird der Drag-Prozess gestartet, indem Effect auf DragDropEffects.All gesetzt wird.
Schließlich werden im DragDrop-Ereignis die "fallengelassenen" Dateien aufgenommen und in ein Array eingelesen.
|
|
|
Private Sub ListBox1_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles _
ListBox1.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub ListBox1_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles _
ListBox1.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim DroppedFiles As String() = _
e.Data.GetData(DataFormats.FileDrop)
For i As Int32 = 0 To DroppedFiles.Length - 1
ListBox1.Items.Add(DroppedFiles(i))
Next
End If
End Sub
|
|
|
|
|
Windows-Version |
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
|
Download (6,3 kB)
|
Downloads bisher: [ 626 ]
|
|
|