Another way to prevent the Default Context menu appearing in a TextBox
Submitted by Rick Rothstein

Applies To

OS:
VB:
NT, 9x, 2000
5, 6

The following code demonstrates one simple way to prevent the default context menu from appearing when the user Right-Clicks in a TextBox. It involves a simple API call, but does not make use of sub-classing. It seems to be safe and reliable without any draw-backs. It does require that you pop up your own context menu though, so if that fits your situation, then you might want to try this technique.

Add the following to a .BAS, .FRM or .CLS

'Place in General declarations
Private Declare Function ReleaseCapture Lib "user32" () As Long

'Place the following code for every textbox where you want to overide the
'default context menu.
Private Sub Text1_MouseDown(Button As Integer, _
                            Shift As Integer, X As Single, Y As Single)
     If Button = vbRightButton Then
        ReleaseCapture
        PopupMenu mnuYourPopUpMenuName
     End If
 End Sub