gpt4 book ai didi

VB.NET DragAndDrop 不适用于控件

转载 作者:行者123 更新时间:2023-12-05 08:59:59 26 4
gpt4 key购买 nike

我正在尝试制作一个使用拖放功能的程序,但是,它仅在我将某些内容拖放到窗体而不是控件上时才有效。如果我尝试使用控件,我只会看到“不可用”光标。

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

最佳答案

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

Dropping a file onto a form (or a form's component) doesn't work if VS is started in Administrator mode.

Grrrrrrrr.....

关于VB.NET DragAndDrop 不适用于控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10623822/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com