【问题标题】:.NET Select USB drive as default FolderBrowserDialog path.NET 选择 USB 驱动器作为默认的 FolderBrowserDialog 路径
【发布时间】:2018-03-09 14:37:01
【问题描述】:

尊敬的所有编程大师,

当前路径(文件夹)是通过单击按钮选择的。

Private Sub SelectButton_Click(sender As Object, e As EventArgs) Handles SelectButton.Click
    FolderBrowserDialog1.ShowDialog()
    Path.Text = FolderBrowserDialog1.SelectedPath

End Sub

将U盘路径设为默认FolderBrowserDialog.SelectedPath有哪些方法?

谢谢!

【问题讨论】:

  • FolderBrowserDialog1.InitialDirectory = "F://" USB 路径

标签: .net vb.net path usb folderbrowserdialog


【解决方案1】:

试试下面的代码:

    Dim folder = New FolderBrowserDialog()
    Dim drives = System.IO.DriveInfo.GetDrives()
    Dim usbDrive = drives.FirstOrDefault(Function(m) m.DriveType = System.IO.DriveType.Removable)
    folder.SelectedPath = usbDrive.RootDirectory.FullName
    If folder.ShowDialog() = DialogResult.OK Then
        MessageBox.Show(folder.SelectedPath)
    End If

【讨论】:

  • 谢谢!奇迹般有效。介意在那里解释一下 Function(m) 吗?在这里编程的新手。谢谢!
  • Function(m) 是一个 lambda 表达式,表示一个函数。您可以通过这里进一步了解 lambda 表达式:Lambda Expressions (Visual Basic)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多