0

我正在开发一个应用程序来读取 XML 文件、获取其数据并填充一些字段。所以,我实现了两种获取文件的方法:通过命令按钮和拖放表单事件。如果我使用存储在计算机文件夹中的文件,一切正常。我可以拖动文件,光标将其外观更改为复制效果等。但是,当我尝试将文件作为 Outlook 的附件拖动时(我的版本是 2010),我看到光标呈现禁止效果并且该文件未被读取。

请看下面我所做的实现,它仅适用于存储在我计算机文件夹中的文件。我想知道我还需要实现什么才能允许从 Outlook 中拖动文件。

先感谢您。

    Private Sub FrmJIG_DragDrop(sender As Object, e As DragEventArgs) _
    Handles Me.DragDrop
    Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
    Dim filestype() As String

    filestype = e.Data.GetData(DataFormats.FileDrop)
    Dim sReader As New StreamReader(filestype(0))

    'get the filename from the file without the path
    Dim file_name As String = Path.GetFileName(filestype(0))

    'check the extension of the file
    If Path.GetExtension(filestype(0)).ToLower() = ".xml" Then
        'Read the xml file
        For Each path In files
            ReadXMLFile(path)
        Next
    Else

        'warning about the file type
        MessageBox.Show("Only XML files are supported!", "Warning!", _
MessageBoxButtons.OK, _
    MessageBoxIcon.Warning)
    End If
End Sub

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub
4

1 回答 1

0

请尝试

Private Sub FrmJIG_DragEnter(sender As Object, e As DragEventArgs) _
Handles Me.DragEnter

    'change the cursor  type to drag and drop type
    If e.Data.GetDataPresent(DataFormats.FileDrop) or e.Data.GetDataPresent("FileGroupDescriptor") Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub
于 2013-04-05T17:34:44.537 回答