2. Slide 2 of 2609/20/13
Module Introduction
+ A dialog box is a special window, which can be used to interact with the user and display
information.
+ It acts as a container that can hold various controls to retrieve information.
+ Dialog boxes are divided into two categories :
- Common dialog boxes are system-defined dialog boxes
- Custom dialog boxes are user-defined dialog boxes.
3. Slide 3 of 2609/20/13
A dialog box is a window that allows you to collect and display related information using
various controls.
Some of the dialog boxes that you have used in Windows are Save As, Color, Print and
Page Setup.
Introduction to Dialog Boxes
4. Slide 4 of 2609/20/13
Elements
A dialog box consists of:
• Title bar displaying caption and the close icon
• Instruction text informing what the user should do (optional)
• Content with controls to select or display information
• Action area having buttons and link labels
• Footnote area explaining about the window (optional)
5. Slide 5 of 2609/20/13
Features
A dialog box is different from forms because of some basic features. These
are:
+ Non-resizable: A dialog box is not resizable and cannot be maximized or
minimized.
+ Usually Modal: A dialog box is usually of modal type. This means that the
user is not allowed to focus on any other window until the dialog box is
closed.
+ Common Set of Buttons and Icons: a dialog box consists of some standard
buttons such as OK and Cancel.It also consists of the Help and Close icons on
its top-right corner.
6. Slide 6 of 2609/20/13
Modal Dialog Box
There are two types of dialog boxes namely : modal and modeless.
+ A modal dialog box does not allow the user to activate any other window in the application
unless the dialog box is closed.
+ A modeless dialog box allows user to focus and work with the same application without
closing the dialog box.
7. Slide 7 of 2609/20/13
Common and Custom Dialog Boxes
+ Common dialog boxes are system-defined dialog boxes such as Open, Save and Print.
These dialog boxes are reusable and hence can be used across various applications.
+ Custom dialog boxes are user-defined dialog boxes. These dialog boxes are useful
when the system-defined dialog boxes do not fulfill certain requirements.
8. Slide 8 of 2609/20/13
"CommonDialog" Class
The CommonDialog class is the base class for all common dialog boxes. This class exists
in the System.Windows.Forms namespace.
9. Slide 9 of 2609/20/13
"ColorDialog" Component
The ColorDialog component is a dialog box that allows you to select system-defined colors
from the color palette.
13. Slide 13 of 2609/20/13
"OpenFileDialog" and "SaveFileDialog" Components
The OpenFileDialog and SaveFileDialog are the most commonly used dialog boxes in
applications. The OpenFileDialog component allows you to open a file and the SaveFileDialog
component allows you to save a file.
14. Slide 14 of 26
09/20/13
"OpenFileDialog" Class
16. Slide 16 of 2609/20/13
"PageSetupDialog" Component
The PageSetupDialog component is a system-defined dialog box, which allows the user to
set the page layout for printing. It provides various options such as the border and margin
adjustments, headers and footers, and portrait and landscape orientation for the page to be
printed.
17. Slide 17 of 2609/20/13
"PageSetupDialog" Class
18. Slide 18 of 2609/20/13
"PrintDialog" Component
The PrintDialog component is a system-defined dialog box that allows you to print the
documents.
20. Slide 20 of 2609/20/13
"PrintPreviewDialog" Control
The PrintPreviewDialog control is used to display the way a document will appear when
printed.
21. Slide 21 of 2609/20/13
"PrintPreviewDialog" Class
22. Slide 22 of 2609/20/13
User-Defined Dialog Boxes
A system-defined dialog box does not always fulfill the requirements of the developers and
users. In such cases, a developer needs to create custom dialog boxes to fulfill the
requirements. To do so, you can convert a form into a user-defined dialog box.
To create a user-defined dialog box:
+ The FormBorderStyle property of the form should be set to FixedDiaiog.
+ The ControlBox, MinimizeBox, and MaximizeBox properties should be set to False.
+ The form must provide the OK and Cancel buttons to either close the dialog box or cancel
any tasks within the dialog box.
+ The AcceptButton property of the form should be used to set the OK button.
+ The CancelButton property of the form should be used to set the Cancel button.
24. Slide 24 of 2609/20/13
Retrieving Information from a Dialog Box
The form that displays the dialog box can retrieve the result of that dialog box by referencing
its DialogResult property.
"DialogResult" Enumeration