Csc301 Chapter 4-1 Menus
Csc301 Chapter 4-1 Menus
program control
CHAPTER 4:
MENUS Display and use the windows common
dialog boxes
MENU SYSTEMS
The menu designer allows you to visually create a custom menu system
For any form in an application
COMPONENTS OF A MENU
SYSTEM
Right-click Menu
Or type a hyphen
item, select Insert
(-) in the menu
then select
item
Separator
A separator bar
will be inserted
above the menu
item
Separator Bar
SEPARATOR BARS
SUBMENUS
▪ predefined standard dialog boxes e.g. opening files, saving files, and selecting
fonts and colors
▪ use common dialog control that can be found in the Toolbox window
(OpenFileDialog, SaveFileDialog, FontDialog, and ColorDialog)
▪ cannot resize
▪ location doesn’t matter, invisible when program runs (appear in component tray
atdesign time)
18
OPENFILEDIALOG CONTROL
▪ open a file either specify the filename(code) or require
user to enter the path and filename
▪ displays a standard WindowsOpen
dialog box
• ability to browse for a file to open
• naming : ofd (e.g. ofdOpenFile)
19
OPENFILEDIALOG CONTROL
▪ Displaying an Open Dialog Box
▪ displaying by calling ShowDialog()
• general form: ControlName.ShowDialog()
• E.g. : ofdOpenFile.ShowDialog()
▪ input validation (whether user has selected file or
not) using:
• Windows.Forms.DialogResult.OK
• Windows.Forms.DialogResult.Cancel
• E.g.:
20
OPENFILEDIALOG CONTROL
▪ The FilterProperty
• specifies type of files visible using Filter property
• E.g. :
*.txt (only text files are
displayed)
*.doc (only Microsoft word
files are displayed)
▪ can set the filter in Property
Window or using coding
• E.g.:
21
OPENFILEDIALOG CONTROL
22
OPENFILEDIALOG CONTROL
23
SAVEFILEDIALOG CONTROL
24
SAVEFILEDIALOG CONTROL
▪ Displaying and Combining All Properties
▪ displaying by calling ShowDialog()
• general form: ControlName.ShowDialog()
• E.g. : sfdSaveFile.ShowDialog()
▪ coding for input validation and combining
properties:
25
COLORDIALOG CONTROL
26
COLORDIALOG CONTROL
• this coding displays the Color dialog box and then sets the text color based
on user choices
27
COLORDIALOG CONTROL
▪ default initial color is black
▪ if want to change the initially selected
color, set in the Color property or using
coding
• Color property :
• Coding :
28
FONTDIALOG CONTROL
▪ displays a standard Windows
Font dialog box
▪ Two (2) types :
• Default Font dialog box
• Font dialog box with colorchoice
▪ found in the ToolboxWindow
• invisible at runtime, appears only in
the component tray at design time
• naming : fd (e.g. fdFont)
29
FONTDIALOG CONTROL
30
FONTDIALOG CONTROL
▪ Hold value representing the font settings selected by user
• e.g. coding - display Font dialog box and sets lblMessage font as selected by
user:
• OR displays a Font dialog box with drop-down list of color, sets lblMessage
font and color as selected by user
31
END OF SUBTOPIC … MENUS