0

我无法使用 OpenFileDialog 类显示多个文件名。我已经选择了Multiselect设置为true,并且可以在DialogBox中选择多个文件,但是TextBox1区域只打印了1个文件。

这是我的代码:

Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    OpenFileDialog1.ShowDialog()
End Sub

Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
    ' Dialog Result
    Dim FilesSelected As DialogResult
    ' Are Files Selected?
    If (FilesSelected = System.Windows.Forms.DialogResult.OK) Then
        ' If Files Identify Array
        Dim file() As String
        file = OpenFileDialog1.FileNames
        For Each file In OpenFileDialog1.FileNames
            TextBox1.Text = (CurDir() & "")
        Next
    End If

End Sub
End Class
4

2 回答 2

0

您每次都在 foreach 循环中覆盖 Text 。

于 2013-08-04T20:54:46.140 回答
0

首先,确保将 TextBox 的MultiLine属性设置为 true 并将其大小调整为可接受的高度。还将 ScrollBars属性设置为 Vertical

然后你的代码可以这样写(没有显式循环)

Dim txt = string.Join(Environment.NewLine, OpenFileDialog1.FileNames)
TextBox1.Text = txt
于 2013-08-04T20:57:24.420 回答