vb.net怎么把一个文件夹的所有文件都添加到listbox里。

2024-11-15 18:48:17
推荐回答(1个)
回答1:

定义一个窗体继承自System.Windows.Forms.Form。

添加以下控件对象到窗体:
Private folderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
Private button1 As System.Windows.Forms.Button
Private listBox1 As System.Windows.Forms.ListBox

给button1的Click事件添加以下处理程序:
Sub Button1Click(sender As Object, e As EventArgs)
If System.Windows.Forms.DialogResult.OK=Me.folderBrowserDialog1.ShowDialog(Me) Then
Me.listBox1.Items.AddRange(System.IO.Directory.GetFiles(Me.folderBrowserDialog1.SelectedPath))
End If
End Sub