Folder Browser Dialog (VB.NET)

OverviewFolder Browser Dialog

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.

Properties

This dialog has not much properties. The normally used properties and their usage is explained below.

  • Description
  • SelectedPath
  • RootFolder
  • ShowNewFolderButton

Description Property

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.

Example Code


  Dim FolderBrowser As New FolderBrowserDialog

        FolderBrowser.Description = "Hello this my description for this dialog. You can write your own here."

  FolderBrowser.ShowDialog()

        FolderBrowser.Dispose()

 

SelectedPath Property

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.

Example Code

  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()

 

RootFolder Property

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

Example Code


  Dim FolderBrowser As New FolderBrowserDialog
        FolderBrowser.RootFolder = Environment.SpecialFolder.MyMusic
        FolderBrowser.ShowDialog()
        FolderBrowser.Dispose()

 

ShowNewFolderButton Property

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.

Example Code


  Dim FolderBrowser As New FolderBrowserDialog
        FolderBrowser.ShowNewFolderButton = False
        FolderBrowser.ShowDialog()
        FolderBrowser.Dispose()

 

Methods 

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

About these ads

About ezonemag
A Webmaster Thats All

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: