Contents
Open Dialog  Sample Help

Sample Description: Open Dialog

Points of Interest

Adding an Open Dialog to your Application

Posting the Open Dialog

Selecting a File

Applying a Selected File

Control

OpenDialog

For Help on Help, Press F1


Open Dialog

The Open Dialog lets users navigate to the file they would like to open by allowing them to select a drive, a directory, and the name of the file to open. In this sample, the caption defaults to "Open." This caption can also be set prior to posting the OpenDialog by setting the OpenDialog's Title property. The default caption for the title bar is "Open," however this may be set by the OpenDialog's Title property before the OpenDialog is posted.

Before displaying the OpenDialog, you can set various options through the OpenDialog's properties that restrict the functionality of the OpenDialog. The following describes a few of the available property options:

Property	Behavior

Filter	Specifies what types of files are displayed in the File list box. By default, no filter is set. If you don't specify the Filter property, the user must explicitly type a filename in the File Name edit box. The user cannot click a name from a list of files filtered to the File list box.

NoNetworkButton	Displays the Network button if True, otherwise hides it.

NoChangeDir	Does not permit directory changes if this property is True.

To run the OpenDialog sample:

1.	Enter a desired text string in the Title box.

2.	Next, click on the various options and checkboxes displayed in the sample form. This sets the various properties that are available in the OpenDialog.

3.	Now click the Open button and select a file from the OpenDialog.

4.	Click the OK button on the OpenDialog. Information obtained from the OpenDialog properties are displayed at the bottom of the sample form.


Adding an Open Dialog to your Application

An open dialog can easily be added to your application for selecting files. This is accomplished by embedding an OpenDialog as an object in your form's property list. In the example shown, the OpenDialog was embedded and given a name "OpenPanel.”

When added to an application, the user can select a filename from various drives and directories. If the Network button option is used, the user may select files from other systems on the network.

Once a file has been selected, information about the file is loaded into the OpenDialog's various properties. This information may be useful for determining the type of action you want to take in your program code.


Posting the Open Dialog

To post an Open Dialog, you may first want to place an informative label in the title area of the Open Dialog, such as "Please select graphics file.” This is done by setting the OpenDialog Title property. For example:  OpenPanel.Title = "Please select graphics file."

In addition, you may want to limit the files being displayed in the file list box by setting the Filter property. For example: OpenPanel.Filter = "Bitmap files (*.bmp)|*.bmp|"  Filters can incorporate multiple file type extensions, thereby allowing more than one type of file to be presented. For example:  OpenPanel.Filter = "System files (*.sys)|*.sys|Config files (*.ini)|*.ini|"

To actually post the OpenDialog, you need only run the dialog's Execute method. For example:  OpenPanel.Execute

If you examine the code found in the btnOpen_Click method, you will see that once the Execute method is issued, your program code is temporarily suspended until either the OK or Cancel button on the Open dialog is clicked.


Selecting a File

Once an Open Dialog is posted, you may select a file by clicking on one of the displayed filenames. The user may change drives by selecting a drive from the drive combobox. The user may also change directories by clicking on various directory names and clicking the OK button. It is important to note that clicking OK on a filename will accept the filename, however, clicking OK on a directory simply changes the currently displayed directory.

Once a filename has been selected, information such as file size, date created, and so on are recorded in the OpenDialog's properties. This information may be useful to your program. Should the user decide to abort the file selection operation, they can simply click the Cancel button.


Applying a Selected File

Once a filename has been selected, you may want your program code to carry out a specific operation on that filename such as opening the file for editing, printing the file, merging the file into your application, etc. In the sample demonstration, only the information about the file that was selected in the Open dialog is displayed.