You are on page 1of 25

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.
CCP-503.14 1
 Sub Topic : Adding functionality to Menus with code
Objectives :
Upon the completion of this period you will be
able to understand about
• Adding Functionality to Menus with Code

CCP-503.14 2
Recap

Designing Menus up to Third Level

CCP-503.14 3
Writing Code for Menu Controls
Menu item get functionality with code

Code is written for click event of Menu items

Every Menu item is listed in code Window

Code can be Written Menu item just like it is written for


other controls

CCP-503.14 4
Menu structure for adding Code

CCP-503.14 5
Writing Code for Menu Controls

 The following code is entered in the Form_Load()


Procedure.

Private Sub Form_Load()


frm Color.BackColor = VBgreen
frm Color.WindowState = 0
Mnu Green.Enabled = False
Mnu Small.Enabled = False
End Sub

CCP-503.14 6
Writing Code for Menu Controls
 Initially the window is small and the items
Form is green in color.

 Hence, the menu items Small and Green


are disabled.

CCP-503.14 7
Initial stage of execution

Disabled

CCP-503.14 8
Initial stage of execution

Disabled

CCP-503.14 9
Writing Code for Menu Controls
The following code is entered in the
MnuRed_Click() Procedure.

Private Sub MnuRed_Click()


frmColor.BackColor = VBRed
MnuRed.Enabled = False
MnuGreen.Enabled = True
MnuBlue.Enabled = True
End Sub

CCP-503.14 10
When Menu Item Red is Clicked

Disabled

CCP-503.14 11
Writing Code for Menu Controls
 The following code is entered in the
MnuBlue_Click()Procedure.

Private Sub MnuBlue_Click()


frmColor.BackColor = VBBLUE
MnuBlue.Enabled = False
MnuGreen.Enabled = True
MnuRed.Enabled = True
End Sub

CCP-503.14 12
When Menu Item Blue is Clicked

Disable
d

CCP-503.14 13
Writing Code for Menu Controls

 The following code is entered in the MnuGreen_Click()


Procedure.

Private Sub MnuGreen_Click()


frmColor.BackColor =VBgreen
MnuGreen.Enabled = False
MnuRed.Enabled = True
MnuBlue.Enabled = True
End Sub

CCP-503.14 14
When Menu Item Green is Clicked

Disabled

CCP-503.14 15
Writing Code for Menu Controls

 The following code is entered in the


MnuLarge_Click() Procedure.

Private Sub MnuLarge_Click()


frmColor.WindowState = 2
MnuLarge.Enabled = False
MnuSmall.Enabled = True
End Sub

CCP-503.14 16
When Menu Item Large is Clicked

Disabled

CCP-503.14 17
Writing Code for Menu Controls
 The following code is entered in the
MnuSmall_Click() Procedure.

Private Sub MnuSmall_Click()


frmColor.WindowState = 0
MnuSmall.Enabled = False
MnuLarge.Enabled = True
End Sub

CCP-503.14 18
When Menu Item Small is Clicked

Disable
d

CCP-503.14 19
Writing Code for Menu Controls
 The following code is entered in the MnuExit_Click()
Procedure.
Private Sub MnuExit_Click()
End
End Sub
 When Exit Menu item is clicked, the application ends

CCP-503.14 20
Summary
 Adding functionality to Menu items with code

CCP-503.14 21
Quiz
1. To set the Form size to maximum WindowState
property to be set to ___.

A) 0
B) 1
C) 2
D) 3

CCP-503.14 22
Quiz
2. Which event of Form is executed first when we run the
Form?
A) Load
B) Click
C) UnLoad
D) Hide

CCP-503.14 23
Assignment
1. Create an application to change height, width of a
command button with a Menu.

CCP-503.14 24
Frequently Asked Questions
1. Explain the process of creating Menus
at run time.

CCP-503.14 25

You might also like