Folder Browser Dialog (VB.NET)
February 20, 2011 Leave a comment
Folder Browser Dialog is Microsoft .Net component. You can find this component in the toolbox under the dialogs tab. This dialog is normally used to browse the folders or to locate a path for the later use in the program, like to set data file reading and writing path. The dialog has not much customization except you can allow or disallow the user to create the new folder. in the appearance of the dialog you can add few words in the Description property, which appears on the top of the dialog.
There are two more buttons on the layout of dialog, Ok button and Cancel button, both buttons has the same function, which is defined through out in the windows environment. After selecting the desired folder user clicks the Ok button and the path is returned in the SelectedPath property that you can use in your program.
This dialog has not much properties. The normally used properties and their usage is explained below.
This property is used to give descriptive detail for which the dialog is being displayed. for example if you are displaying this dialog box for setting the root folder for your application data file, preferences file, cookies, etc.
Dim FolderBrowser As New FolderBrowserDialog FolderBrowser.Description = "Hello this my description for this dialog. You can write your own here." FolderBrowser.ShowDialog() FolderBrowser.Dispose()
This property is read/write property. This property returns the selected path in response, when OK button is clicked, otherwise it returns the empty string. if you set this property with any valid path before calling the ShowDialog method, it will take you directly to that folder location.
Dim FolderBrowser As New FolderBrowserDialog If FolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then MsgBox(FolderBrowser.SelectedPath) Else MsgBox("You have canceld the dialog.") End If FolderBrowser.Dispose()
This property is read/write, It can set the default root for user, defined in the system special folders. It accepts the Special Folder as a property value. The SpecialFolder is enumerator constants defined in the Environment class. Default value is zero which represents the Desktop. You can get further reference for special folder enumerator constants here
Dim FolderBrowser As New FolderBrowserDialog FolderBrowser.RootFolder = Environment.SpecialFolder.MyMusic FolderBrowser.ShowDialog() FolderBrowser.Dispose()
This property enables or disables the make new folder button on the dialog layout. This way you can restrict the user from creating the new folder in the root or in sub folders. Default value for this property is True.
Dim FolderBrowser As New FolderBrowserDialog FolderBrowser.ShowNewFolderButton = False FolderBrowser.ShowDialog() FolderBrowser.Dispose()
This dialog has only one significant method ShowDialog. it invokes the FolderBrowser object as Modal dialog and displays on the screen. It returns the dialog enumerator constant as dialog result. for its example code see above examples.
Download source code here