FP613 :
.NET TECHNOLOGY
2.4 Apply Dialog Boxes.
2.4 APPLY DIALOG BOXES.
By the end of the class, students should be
able to:
2.4.1 Explain the usage of dialog boxes.
2.4.2 Create dialog boxes example color,
fonts, print, open and save.
2.4.3 Dialog boxes in application.
DIALOG BOXES
Dialog Boxes
You can use dialog boxes in
your project for specify
color, fonts, printing,
opening and saving files.
Before calling the dialog
box your must create
Common Dialog Control on
your form first
DIALOG BOXES
After placing a common dialog control on
your form, dialog box can display at run time
using the ShowDialog method.
In coding, specify which dialog box you need
to view using show method.
DialogObject.ShowDialog()
OPENFILE DIALOG & SAVEFILE DIALOG
OpenFileDialog control – SaveFileDialog
obtain a file name from control – allows
the user. user to select a
file(s) to save.
OPENFILE DIALOG & SAVEFILE DIALOG
Set the properties of the dialog box and call
the ShowDialog method to display the
OpenFileDialog or SaveFileDialog.
OpenFileDialog
Standard Prefix : ofd
Example : ofdOpenFile.ShowDialog()
SaveFileDialog
Standard Prefix : sfd
Example : sfdSaveFile.ShowDialog()
OPENFILE DIALOG & SAVEFILE DIALOG
Properties:
1. CheckFileExist /CheckPathExist – determine whether
user can specify a file/path name that does not exist.
2. FileName – gets a string containing the file name to
open. Contains both path and file name.
3. Filter – control the types of file that will displayed for
selection.
4. FilterIndex – work with Filter property and has an
index. It defines which filter in a list of filters is active.
5. InitialDirectory – defines initial folder to open / save a
file.
6. MultiSelect – if True, allows user to select multiple files
to open/save
7. Title – defines the text that appear in the title bar for
open/save dialog control
OPENFILE DIALOG & SAVEFILE DIALOG
Examples:
ofdMain.Filter = “Text Files (*.txt) |*.txt|” & _
“Rich Text (*.rtf) |*.rtf|All Files (*.*)|*.*”
ofdMain.FilterIndex = 2
ofdMain.ShowDialog()
COLOR DIALOG BOX
2 section: display basic and allows the user
to define custom colors.
SETTING COLOR – COLOR DIALOG BOX
Set the properties of the dialog box and call
the ShowDialog method to display the
ColorDialog.
Standard Prefix : cd
Example : cdSelectColor.ShowDialog()
SETTING COLOR – COLOR DIALOG BOX
Syntax : DialogObject.ShowDialog()
Properties :
1. AllowFullOpen – determine whether user can
define custom color. True: Define Custom Colors
button enabled, False : disabled
2. AnyColor – whether displays all color from the set
of basic colors
3. CustomColors – gets/sets the custom color
displayed in the ColorDialog
4. FullOpen – determine whether the custom colors
part of the dialog box appear when the
ColorDialog is first displayed. When displayed, the
Define Custom Colors button is disabled.
SETTING COLOR – COLOR DIALOG BOX
The color selected by the user is stored in the Color
Property. You can assign this property to another
object, such as a control or the form.
Examples:
cdSelectColor.ShowDialog()
‘Show dialog box
lblDisplay.BackColor=cdSelectColor.Color
‘Color
FONT DIALOG BOX
Enabled user to select and setting font
SETTING FONT – FONT DIALOG BOX
Set the properties of the dialog box and call
the ShowDialog method to display the
FontDialog.
Standard Prefix : fd
Example : fdSelectFont.ShowDialog()
SETTING FONT – FONT DIALOG BOX
Statement : fdSelectFont.ShowDialog()
Properties :
1. Color – defines basic font color
2. Font – defines the selected font (installed)
3. MinSize / MaxSize – control min/max font size
selectabel by the user.
4. ShowApply –display an Apply button. If set True
and user clicks, Window will fire the Apply Event.
5. ShowColor – if set True, allows user to select
color in dialog
6. ShowEffect – control whether or not the user can
select font effects such as underlining.
Examples:
fdSelectFont.ShowDialog()
‘Show dialog box
lblDisplay.Font=fdSelectFont.Font
‘Select Font
lblDisplay.Font=fdSelectFont.Color
‘Select Font Color