This document provides code examples for creating and handling popup menus in VB. It shows how to display a popup menu on right click, determine which menu item was selected, and toggle font styles like bold, italic, and underline when their corresponding menu items are clicked. Code is presented for handling the click events of bold, italic, and underline menu items to toggle the corresponding font properties and checked state of the menu items.
1 of 3
More Related Content
Menu vb
1. Code help for Menu, pop up menu
If Button = vbRightButton Then PopupMenu Me.mnuPopup
Private txtName_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
Single)
If Button=vbRightButton Then
PopupMenu mnuEdit
End If
End Sub
How do I find out what menu item was clicked
str = popMenu.Name
Select Case str
Case "mCut"
MsgBox "cut"
Case "mPaste"
MsgBox "paste"
Case "mProperties"
MsgBox "pro"
End Select
Popup menu coding
Private Sub lblTestText_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
If Button = vbRightButton Then
PopupMenu mnuPopUpFormat, vbPopupMenuRightButton
End If
End Sub
2. Code for bold
Private Sub mnuBold_Click()
If mnuBold.Checked Then
lblTestText.FontBold = False
mnuBold.Checked = False
Else
lblTestText.FontBold = True
mnuBold.Checked = True
End If
End Sub
Code the mnuItalic_Click and mnuUnderline_Click events in a similar fashion as shown
below.
Private Sub mnuItalic_Click()
If mnuItalic.Checked Then
lblTestText.FontItalic = False
mnuItalic.Checked = False
Else
lblTestText.FontItalic = True
mnuItalic.Checked = True
End If
End Sub
Private Sub mnuUnderline_Click()
If mnuUnderline.Checked Then
lblTestText.FontUnderline = False
mnuUnderline.Checked = False
Else
lblTestText.FontUnderline = True
mnuUnderline.Checked = True
End If
End Sub
MsgBox "Code for 'Print' goes here.", vbInformation, "Menu Demo"
Private Sub mnuBold_Click()
If mnuBold.Checked Then
lblTestText.FontBold = False
mnuBold.Checked = False