Sunteți pe pagina 1din 28

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name of the faculty : G. Radha
Designation : Lecturer
Branch : CCP
Institute : 026 - SG Govt. Polytechnic,
Adilabad
Year / Semester : III Year / V Semester
Subject : Visual Basic – I
Subject Code : CCP - 503
Topic : Understand Menus and
Common dialogue control
Duration : 50 Mts.
Sub Topic : Common Dialogue Control
Teaching Aids : Animations & Images

CCP-503.20 1
Recap

 Custom Dialogue Control.

CCP-503.20 2
Objectives :

Upon the completion of this period ,you will be


able to understand about
 Common Dialogue Control.

CCP-503.20 3
Common Dialogue Control

 The Common Dialogue Control is a control that


displays the commonly used dialogue boxes such as
Save As, Color, Font, Print and Open

 When a Common Dialogue Control is drawn on a


Form, it automatically resizes itself and it is invisible at
run time

CCP-503.20 4
Add a Common Dialogue Box to a Form

Follow these steps :

 Components is selected from the Project Menu


which displays a components box.

 After ensuring that Microsoft Common Dialogue


6.0 Control check box has a check mark in it, the
OK button is clicked.

CCP-503.20 5
Example on Common Dialogue Control

 A new Standard EXE Project is opened and the


Form and the Project files are saved as
Cmdialog.frm and Cmdialog.vbp.

 The application is designed as per the following


table.

CCP-503.20 6
Example on Common Dialogue Control

Object Property Settings

Form Caption The Common


Dialogue Program
Name Cmdialog

Commondialog Cancel Error True

Name Commondialog1

CCP-503.20 7
Example on Common Dialogue Control
The following are Menu Items to be added to
the Form.
Caption Name

&File MnFile

….Color MnColor

….Open MnOpen

….- MnSep

….E&xit MnExit

CCP-503.20 8
Example on Common Dialogue Control

CCP-503.20 9
Example on Common Dialogue Control
The following code is entered in the
MnColor_Click() procedure
Private Sub MnColor_Click()
On Error GoTo errortrap
CommonDialog1.Action = 3 'Display Color Dialogue Box'
Cmdialog.BackColor = CommonDialog1.Color
Exit Sub
errortrap:
MsgBox "Dialog Box is Cancelled"
End Sub

CCP-503.20 10
Example on Common Dialogue Control

 Whenever Color Menu is selected it displays a


Color Dialogue Box.
 Before displaying the dialogue box, the
MnColor_Click() procedure sets an errortrap. The
purpose of Errortrap is to detect the error during the
display of dialogue box.
 We have set the CancelError property of the
CommonDialog Control to True at design time.

CCP-503.20 11
Example on Common Dialogue Control
 Therefore, if the Cancel button is pressed when
the dialog box is displayed, the Errortrap, which
has been set, displays the message “Dialog Box is
Cancelled” and the dialog box disappears.

 However, if a specific color is selected from the


dialog box and OK button is clicked the BackColor
of the Form is changed to that particular Color.

CCP-503.20 12
Color Dialog Box

CCP-503.20 13
Changing of Form Back Color

CCP-503.20 14
When the Cancel Button is Clicked

CCP-503.20 15
Example on Common Dialogue Control
The following code is entered in the
MnOpen_Click() procedure
Private Sub MnOpen_Click()
Dim Filter As String
On Error GoTo errortrap
Filter = "all Files (*.*) | *.*"
CommonDialog1.Filter = Filter
CommonDialog1.Action = 1
MsgBox "Selected File is:" +

ommonDialog1.FileName
Exit Sub
errortrap:
MsgBox "Dialog box is cancelled"
Exit Sub CCP-503.20 16
End Sub
Example on Common Dialogue Control

 The above procedure displays an Open Dialog Box.


 Before displaying the dialog box, the first statement of the
MnOpen_Click() procedure sets an errortrap the purpose of
which is to detect an error during display of the dialog box
 If the Cancel button is pressed when the dialog box is displayed
the errortrp, which has been set, displays the message “Dialog
Box is Canceled” and the dialog box is disappear
 However, if a specific File is selected from the dialog box, the
name of the selected File is displayed as message box

CCP-503.20 17
Open Menu Control clicked

CCP-503.20 18
When a File is Selected in Dialog Box

CCP-503.20 19
When the Cancel Button is Clicked

CCP-503.20 20
Example on Common Dialogue Control

The following code is entered in the


MnExit_Click() procedure :
Private Sub MnExit_Click()
End
End Sub

The above procedure terminates the application.

CCP-503.20 21
Example on Common Dialogue Control

 Like the Color and Open dialog boxes the properties


of the Common Dialog Control may be used to
determine the user’s response to the dialog box.

 The Action property 4 displays the Font Dialog Box


and 5 displays the Print Dialog Box.

CCP-503.20 22
Summary
 Common Dialogue Control.

CCP-503.20 23
Quiz

CCP-503.20 24
• The option of common Dialog box that
helps in font selection is

A) 4
B) 2
C) 1
D) 6

CCP-503.20 25
----------------- is used to display
commonly used Dialogue Boxes?

A) Custom Dialogue Box


B) Common Dialogue Control
C) Standard Dialogue Box
D) Pre-defined Dialogue Box

CCP-503.20 26
Frequently Asked Questions

1. Write short notes on Common Dialog Control

3. Develop an application to change select fonts


through common dialog box

CCP-503.20 27
Assignment

1. Develop an application using common


dialog box to print file

CCP-503.20 28

S-ar putea să vă placă și