Title: Distance Learning Center
1Distance Learning Center
- Lecture 10
- Introduction to Visual Basic
- Programming
- Melissa Lin, IT Consultant
- HenEm, Inc. Parkville, Missouri
- linm_at_ipfw.edu
- http//www.etcs.ipfw.edu/linm
2Lecture 10
- Menus
- Designer
- Submenus
- Properties
- Dialog Boxes
- Color
- Font
3Menus
- Menus consist of a menu bar containing menus,
each of which drops down to display a list of
menu items. - Designer to define and develop menus and menu
items to the form - Properties to hold attributes of each object
- Submenus - a menu within a menu
- Each menu Item has name properties and click
events
4Menus
- Add Menu Items control to a form
- You must add a MainMenu control from the toolbox
- Type text over the word Type Here appear at the
top of the form - Then the words Type Here appear both below the
menu name and to the right of the menu name - Add submenu by moving to the right of a menu
item and typing the next items text. - Drop-down list of commands
- Have name properties
- Have click events to write code
- Note To activate the menu designer by clicking
on the menu at the top of the form To deactivate
the menu by clicking elsewhere on the form.
5Creating a Menu
- MainMenu
- Create menus
- Use keyboard access commands (x) - Alt-x
Type name of menu
MainMenu control added to Form
6Creating a Menu Sub Menu
Type File
Create submenus by moving to the right of a menu
item and typing the next item's text
7Define Property
Type filePrintMneuItem
Type fileMenu
Type Print
Type File
8Separator Bar
- To insert a separator bar, right-click on the
menu designer where you want the separator bar to
appear and choose Insert Separator from the
context menu.
9Hands-On Creating a Menu
- The steps to write the project
- Define the GUI with
- File, Edit, Display Help
- Print Style Summary
About -
- Exit Font Instruction
- Color
- Have a separator bar inside Display menu
- Set the properties of each object as you have
planned - Write the code working from the pseudcode,
write each event procedure - When completed, to ensure the tab order is set
correctly
10Planning GUI Design
File Edit Display Help
Print Style Summary About
Exit Font Instruction
Color
11Define GUI
12Define GUI (continued)
13Define Properties
14Coding the Menu
- Name the menus e.g. fileMenu, fileExitMenuItem,
helpMenu - Each menu item has a Click event
- Private Sub fileExitMenuItem_Click
- End Sub
- Private Sub helpMenu_Click
- End Sub
- Menu Item Properties
- Checked (fileMenu.CheckedFalse)
- Enabled (fileMenu.EnabledFalse)
- Visible (fileMenu.VisibleTrue)
15Coding the Menu (continued)
Private Sub helpAboutMenuItem_Click(ByVal sender
As _ System.Object, ByVal e As System.EventArgs)
Handles _ helpAboutMenuItem.Click
MessageBox.Show("Programmed by Melissa Lin", _
"About My Program", MessageBoxButtons.OK, _
MessageBoxIcon.Information) End Sub
16Coding the Menu (continued)
Private Sub displaySummaryMenuItem_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles displaySummaryMenuItem.C
lick If DdisplaySummaryMenuItem.Checked
Then 'Hide the summary
displaySummaryMenuItem.Checked False
Else 'show the summary
displaySummaryMenuItem.Checked True End
If End Sub
17Separator Bars
- Used for grouping menu items according to their
purpose - Visually represented as a bar across the menu
- Create using one of two methods
- Typing a single hyphen for the text
- Right-click on Menu Designer where you want
separator bar and choose Insert Separator
18Menu Design Standards
- Follow the industry standards for Windows for
names, order/location, access keys, shortcut keys - Basic Main Menus
File Edit View Format Help
- Standard File Menu
- New (Ctrl N)
- Open (Ctrl O)
- Close
- Save As
- Save (Ctrl S)
- Print (Ctrl P)
- Exit
- Standard Edit Menu
- Undo (Ctrl Z)
- Cut (Ctrl X)
- Copy (Ctrl C)
- Paste (Ctrl V)
- Find (Ctrl F)
- Replace (Ctrl H)
19System Objects and Events
WithEvents helpAboutMenuItem As
System.Windows.Forms.MenuItem
Private Sub helpAboutMenuItem_Click(ByVal sender
As _ System.Object, ByVal e As System.EventArgs)
Handles _ helpAboutMenuItem.Click
MessageBox.Show("Programmed by Melissa Lin", _
"About My Program", MessageBoxButtons.OK, _
MessageBoxIcon.Information) End Sub
20Common Dialog Boxes
- Predefined standard dialog boxes for
- Color selection
- Font selection
- (File Opening and Saving)
- (Printing and Previewing)
- Add the Common Dialog control to form
- Appears in the Component Tray, pane at bottom of
Form Designer where non-display controls are shown
21Common Dialog Boxes (continued)
ExampleProjDialogBox
22Color Font Dialog Boxes
Default Font, Style, and Size
Default Color
23Code to Use Common Dialog Box for Fonts
- Syntax DialogObject.ShowDialog()
- Private Sub fontButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles fontButton.Click - 'Change Font of Label
- With FontDialog1
- .ShowDialog()
- fontLabel.Font .Font
- End With
- End Sub
24Common Dialog Box
25Use Common Dialog Box for Color
Private Sub backColorButton_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles backColorButton.Click 'Change
BackColor of Label With ColcoDialog1
.ShowDialog()
fontLabel.BackColor .Color End With End
Sub Private Sub foreColorButton_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnForeColor.Click
'Change ForeColor of Label With
ColorDialog1 .ShowDialog()
fontLabel.ForeColor .Color End
With End Sub
26Common Dialog Box - BackColor
Click
27Common Dialog Box - ForeColor
Click
28Exit Message Box
Private Sub exitButton_Click(ByVal sender As
System.Object, _ ByVal e As System.EventArgs)
Handles exitButton.Click
MessageBox.Show("Exit - DialogBox", _
"Using DialogBox", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Me.Close() End Sub
29Summary
- Menus
- Designer
- Submenus
- Properties
- Dialog Boxes
- Color
- Font
- Next
- Context menus
- Passing Arguments to procedures
30Question?