2017-09-28 4 views
0

すべてのプログラミングの専門家に.NETデフォルトのFolderBrowserDialogパスとしてUSBドライブを選択

現在、ボタンをクリックするとパス(フォルダ)が選択されます。

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

End Sub 

デフォルトFolderBrowserDialog.SelectedPathとしてメイクUSBドライブパスの方法は何ですか?

ありがとうございます!

+0

'FolderBrowserDialog1.InitialDirectory = "F://"' USBパス – kiLLua

答えて

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 
+0

ありがとうございます!魅力のように動作します。 Function(m)に少し説明するのを忘れないでください。ここでプログラミングを学ぶ。ありがとう! – Tim

+0

関数(m)は関数を表すラムダ式です。ここでラムダ式についてさらに学習することができます:[Lambda Expressions(Visual Basic)](https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures /ラムダ式) – WPInfo

関連する問題