gpt4 book ai didi

.net - 拖放以获取文件路径

转载 作者:行者123 更新时间:2023-12-01 19:40:12 25 4
gpt4 key购买 nike

这是一个我无法开始工作的例子。我按照说明进行操作,但是当我尝试将文件拖放到表单中时,它不允许我这样做,并且给我提供了“不可用”光标。

这很容易。只需将 AllowDrop 属性设置为 True 即可启用drap-and-drop,并处理 DragEnter 和 DragDrop 事件。在 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

最佳答案

Imports System.IO

Public Class Form1

Private Sub Form1_Load(sender As Object, e As 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 theFiles() As String = CType(e.Data.GetData("FileDrop", True), String())
For Each theFile As String In theFiles
MsgBox(theFile)
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
End Class

关于.net - 拖放以获取文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15037128/

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