Common Dialogs


A dialog is a window that is displayed within the context of another window. With a dialog, you can ask the user to enter some data before the flow of the program continues. A common dialog is a dialog used to get information from the user that most applications will typically require, such as the name of a file, and is a part of the Windows operating system.

The classes you get with the Microsoft .NET Framework are shown in Figure 16-1.

image from book
Figure 16-1

All these dialog classes, except the PrintPreviewDialog, derive from the abstract CommonDialog base class that has methods to manage a Windows common dialog.

The CommonDialog class defines the following methods and events common to all common dialog classes.

Public Instance Methods and Events

Description

ShowDialog()

This method is implemented from the derived class to display a common dialog.

Reset()

Every derived dialog class implements the Reset() method to set all properties of the dialog class to their default values.

HelpRequest

This event is thrown when the user clicks the Help button on a common dialog.

All these dialog classes wrap up a Windows common dialog to make the dialog available for .NET applications. PrintPreviewDialog is an exception because it adds its own elements to a Windows form to control the preview of a print, and hence is not really a dialog at all. the OpenFileDialog and SaveFileDialog classes derive from the abstract base class FileDialog that adds file features that are common to both the opening and closing file dialogs.

The following list provides an overview of how the different dialogs can be used:

  • To let the user select and browse files to open, use the OpenFileDialog. This dialog can be configured to allow the selection of a single file or multiple files.

  • With the SaveFileDialog the user can specify a filename and browse for a directory in which to save files.

  • The PrintDialog is used to select a printer and set the printing options.

  • To configure the margins of a page, the PageSetupDialog is usually used.

  • The PrintPreviewDialog is one way to preview on the screen what is to be printed on paper, with options such as zoom.

  • The FontDialog lists all installed Windows fonts with styles and sizes, and it provides a preview to select the font of choice.

  • The ColorDialog class makes it easy to select a color.

  • For selecting and creating directories, the dialog FolderBrowserDialog can be used. This dialog is new with .NET 2.0.

    Note

    I have seen some applications developed (by the same company) where not only were common dialogs not reused, but also no style guide was used for building custom dialogs. The functionality of these dialogs was not consistent, with some buttons and other controls found in different locations, such as the OK and Cancel buttons being reversed between dialogs.

    Sometimes that inconsistency can be found within one application. That's frustrating for the user, and it increases the time required to complete a task.

    Important

    Be consistent in the dialogs you build and use! Consistency can be easily attained by using the common dialogs.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net