|
通过将 AllowDrop属性设置为True并处理 DragEnter和 DragDrop事件,才能启用drap-and-drop.
在DragEnter事件处理程序中,您可以检查数据是否是要使用DataFormats类的类型.
在DragDrop事件处理程序中,使用DataEventArgs的Data属性来接收实际数据.
例:
Private Sub Form1_Load(sender As System.Object,e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
End Sub
Private Sub Form1_DragDrop(sender As System.Object,e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
For Each path In files
MsgBox(path)
Next
End Sub
Private Sub Form1_DragEnter(sender As System.Object,e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
|
|