VB.NET calls the browsing directory dialog
MONTAQUE
Overview:
We all know that the dialog box that opens a file in .NET is easy to define an instance of an OpenFileDialog class to use it directly. Sometimes we need to let users choose a working directory, or a system directory, and is searching for a similar OpenDirectoryDialog class? Of course, it is best to have one, so it is convenient. In fact, the system does not provide such a class. Here we use a short code to build this directory browsing dialog.
thought:
In the reference to the project, browse, you will find a system.designer.dll, and the default this DLL is not referenced by the project, we will introduce it to the project today. There is a FoldernameEditor class under System.Windows.Forms.design, is actually a directory browsing dialog, but this class cannot be used directly, you must inherit. Look at the following code:
For modularization, we create a new Class in the project, named OpenDirectoryDialog, enter the following code:
Code:
Imports System.Windows.Forms
Public Class FolderBrowser
Inherits System.Windows.Forms.design.FoldernameEditor
Public Shared Function Showdialog () AS String
DIM FB AS New FolderBrowser ()
'Dialog
fb.description = "SELECT A DIRECTORY TO SCAN"
'Default is the system's desktop directory
Fb.startLocation = design.FoldernameEditor.FolderBrowserfolder.desktop
'Dialog
Fb.style = design.FoldernameEditor.FolderBrowSerstyles.ShowTextBox
fb.showdialog ()
Return fb.directoryPath
END FUNCTION
END CLASS
After compiling, we can use this Class directly.
The call is as follows:
Debug.writeline (OpenDirectoryDialog.Showdialog ())
We will see the following dialog:
Reference: MS-Help: //ms.vscc/ms.msdnvs.2052/cpref/html/frlrfsystemwindowsformsterFoldernFoldernAmeEditorClasstopic.htm