Add pop-up menu support to the Rich Textbox control

While Visual Basic provides an easy way to create shortcut menus, some controls
such as rich text boxes don't inherently support pop-up menus. To overcome this
obstacle, you can take advantage of the MouseDown() event. Visual Basic triggers
this event when you press the mouse button. To provide a pop-up menu, create a
shortcut menu, then simply call it in the control's MouseDown() event.

To see how this works, add a Rich Textbox control to a sample form. Next, select
Tools | Menu Editor from Visual Basic's IDE menu bar, and create a simple menu
with one or two items. Then, switch to the form's code window, and enter

Private Sub RichTextBox1_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Me.PopupMenu Menu
End IF
End Sub

You might also like...

Comments

ElementK Journals

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila” - Mitch Ratcliffe