我正在尝试制作一个使用拖放功能的程序,但是,它仅在我将某些内容拖放到表单而不是控件时才有效。如果我尝试使用控件,我只会得到“不可用”光标。
AllowDrop 属性是在属性栏中设置的,我也是在表单加载时设置的。我不知道为什么我仍然不能放下东西;以前有人遇到过这个问题吗?
当前代码:
Public Class Main
Private Sub Main_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If e.Data.GetDataPresent("FileDrop", True) = True Then
Dim Files() As String
Dim i As Integer
Files = e.Data.GetData(DataFormats.FileDrop)
For i = 0 To Files.Length - 1
FileList.Items.Add(Files(i))
Next
End If
End Sub
Private Sub Main_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
End If
End Sub
Private Sub Main_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.AllowDrop = True
FilePath.AllowDrop = True
FileList.AllowDrop = True
End Sub
End Class