VB.NET DragAndDrop 不适用于控件

Tos*_*eox 2 vb.net drag-and-drop

我正在尝试制作一个使用拖放功能的程序,但是,它仅在我将某些东西拖放到表单上时才起作用,而不是在控件上。如果我尝试使用控件,我只会得到“不可用”光标。

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
Run Code Online (Sandbox Code Playgroud)

小智 5

我知道这是一个旧线程,但我会发布我发现的内容,以防其他人像过去 2 个小时一样在那里拔头发。

如果 VS 在管理员模式下启动,则将文件拖放到表单(或表单的组件)上将不起作用

呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜