Professional Documents
Culture Documents
Menus, Common Dialog Boxes, Sub Procedures and Function Procedures
Menus, Common Dialog Boxes, Sub Procedures and Function Procedures
Menus, Common Dialog Boxes, Sub Procedures and Function Procedures
McGraw-Hill
Objectives
Create menus and submenus for program control
Display and use the Windows common dialog boxes
Create context menus for controls and the form
Write reusable code in sub procedures and function
procedures and call the procedures from other
locations
5-2
Menus
Menu Bar
Contains menus which drop down to display list of
menu items
Can be used in place of or in addition to buttons to
execute a procedure
Menu items are controls with properties and events
Defining Menus (1 of 2)
MenuStrip component is
added to a form
MenuStrip is a container to
which ToolStripMenu Items,
ToolStripComboBoxes,
ToolStripSeparators, and
ToolStripTextBoxes can be
added
5-4
Defining Menus
(2 of 2)
5-5
Enter and change the Text property for each menu and
menu item using the Menu Designer or make the
changes in the Text property using the Properties
window
5-6
5-7
5-8
Submenus
Filled triangle to the right
of the menu item
indicates to the user the
existence of a submenu
Create submenus by
moving to the right of a
menu item and typing the
next item's text
5-9
Separator Bars
Used for grouping menu
items according to their
purpose
Visually represented as a
bar across the menu
To create a separator
bar, add a new menu
item and click on its
drop-down arrow
5-10
Menu Properties
Enabled property, True/False-can be set at design or
run time
Checked property, False/True-can be set at design or
run time
Used to indicate that an option is selected
5-12
5-13
5-14
5-15
5-16
titleLabel.BackColor = ColorDialog1.Color
5-17
5-19
5-20
Calling
Procedure
5-23
ByRef -reference
Sends a reference to the memory location where the
original is stored and therefore the procedure may
change the arguments original value can be altered
5-24
5-26
Function Example
Private Function Commission(ByVal salesAmountDecimal As Decimal) _
As Decimal
If salesAmountDecimal < 100D Then
Commission = 0D
Function
Else
Commission = 0.15 * salesAmountDecimal
End If
End Function
Private Sub calculateButton_Click( )
Calling
Dim salesDecimal As Decimal
Procedure
salesDecimal = Decimal.Parse(salesTextBox.Text)
commissionLabel.Text = Commission(salesDecimal.ToString("C"))
End Sub
5-27
End Function
paymentLabel.Text = Payment(Decimal.Parse(rateTextBox.Text), _
Decimal.Parse(yearsTextBox.Text), _
Calling Procedure
Decimal.Parse(principalTextBox.Text)).ToString( )
5-28
5-29