Вы находитесь на странице: 1из 24

9/12/2013

Slide 1 of 13

Session 5
Dialog Boxes

9/12/2013

Slide 2 of 26

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.

9/12/2013

Slide 3 of 26

Introduction to Dialog Boxes


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.

9/12/2013

Slide 4 of 26

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)

9/12/2013

Slide 5 of 26

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.

9/12/2013

Slide 6 of 26

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.

9/12/2013

Slide 7 of 26

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.

9/12/2013

Slide 8 of 26

"CommonDialog" Class
The CommonDialog class is the base class for all common dialog boxes. This class exists in the System.Windows.Forms namespace.

9/12/2013

Slide 9 of 26

"ColorDialog" Component
The ColorDialog component is a dialog box that allows you to select system-defined colors from the color palette.

9/12/2013

Slide 10 of 26

"ColorDialog" Class

9/12/2013

Slide 11 of 26

"FontDialog" Component
The FontDialog component allows you to select different fonts that are installed in the system.

9/12/2013

Slide 12 of 26

"FontDialog" Class

9/12/2013

Slide 13 of 26

"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.

9/12/2013

"OpenFileDialog" Class

Slide 14 of 26

9/12/2013

Slide 15 of 26

"SaveFileDialog" Class

9/12/2013

Slide 16 of 26

"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.

9/12/2013

Slide 17 of 26

"PageSetupDialog" Class

9/12/2013

Slide 18 of 26

"PrintDialog" Component
The PrintDialog component is a system-defined dialog box that allows you to print the documents.

9/12/2013

Slide 19 of 26

"PrintDialog" Class

9/12/2013

Slide 20 of 26

"PrintPreviewDialog" Control
The PrintPreviewDialog control is used to display the way a document will appear when printed.

9/12/2013

Slide 21 of 26

"PrintPreviewDialog" Class

9/12/2013

Slide 22 of 26

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.

9/12/2013

Slide 23 of 26

9/12/2013

Slide 24 of 26

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

Вам также может понравиться