2012-01-18 195 views
4

我只是在Visual Studio 2010中搞亂Visual Basic。任何人都知道我會如何做一個「瀏覽文件夾(或文件)」按鈕?我真的是新來的VB和我只是尋找一些簡單的幫助:)VB瀏覽按鈕

回答

6

在窗體上放置一個按鈕,處理單擊事件,並使用FolderBrowserDialog

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click 
    Using fld As New FolderBrowserDialog() 
    If fld.ShowDialog() = Windows.Forms.DialogResult.OK Then 
     MessageBox.Show("Selected " & fld.SelectedPath) 
    End If 
    End Using 
End Sub 

選擇文件,使用OpenFileDialog類:

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles 
    Using ofd As New OpenFileDialog() 
    If ofd.ShowDialog() = DialogResult.OK Then 
     MessageBox.Show("Selected " + ofd.FileName) 
    End If 
    End Using 
End Sub