Popup Menu

Program to implement the working of popup menu on textbox.

Sol.
1. Start Visual Basic by clicking on the Start Button => All programs => Microsoft visual studio 6.0 => Microsoft Visual Basic 6.0

2. Then you can see New project Dialogbox select standard Exe project then click open button.

3. Now you have a Form Control. Change Form Caption property to “Popup Menu” , Borderstyle to "1-fixed single" ,Startupposition to “2-CenterScreen” and Set an Icon to the Form control by using Icon Property ( Click on --- ellipse button and select an icon from C:\Program Files\Microsoft Visual Studio\COMMON\Graphics\Icons\Computer\Mouse02.ICO then click Open button).

4. Add following controls to the form control

Sr. No
Control
Properties
Settings
1
Textbox         
Name
Text
Font
txtsample
Sample Text for Formatting
Times New Roman, Regular, 20 pts
2
Commandbutton
Caption
Cancel
E&xit
True
5. Click on the Command1 button and write codes in between Command1_Click () event procedure.

Private Sub Command1_Click()
End
End Sub


6. Click Ctrl+E key or press menueditor icon on standard toolbar then you can see menueditor dialogbox first uncheck visible checkbox then write caption & name property according to given table

Main Menu
Sr. No
Caption
Name
1
Format
Mnuformat
7. Before writing submenus captions click right arrow button on the menu editor dialogbox.

Sub-Menu
Sr. No
Caption
Name
1
Grow
Mnugrow
2
Shrink
Mnushrink
3
Bold
Mnubold
4
Italics
Mnuitalics
5
Regular
Mnuregular
6
Bold Italics
Mnubolditalics

8.Then write codes as follows:

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
PopupMenu mnuformat
End If
End Sub
Private Sub mnubold_Click()
If txtsample.FontBold = True Then
txtsample.FontBold = False
Else
txtsample.FontBold = True
End If
txtsample.FontItalic = False

End Sub

Private Sub mnubolditalics_Click()
txrtsample.FontBold = True
txtsample.FontItalic = True

End Sub

Private Sub mnugrow_Click()
txtsample.FontSize = txtsample.FontSize + 1
End Sub

Private Sub mnuitalics_Click()
If txtsample.FontItalic = True Then
txtsample.FontItalic = False
Else
txtsample.FontItalic = True
End If
txtsample.FontBold = False

End Sub

Private Sub mnuregular_Click()
txtsample.FontBold = False
txtsample.FontItalic = False

End Sub

Private Sub mnushrink_Click()
txtsample.FontSize = txtsample.FontSize – 1
End sub

9. Now Start project using start button on the standard toolbar or using F5 shortcut key on the keyboard.