Link to home
Start Free TrialLog in
Avatar of craigdawson
craigdawson

asked on

Can system right-click invoked pop-up menu be disabled?

Is it possible with VB5 to disable the system pop-up menu that appears when right-clicking on a text box?  The Paste option allows the user to circumvent validation in my app.  If not, can an application be instructed to ignore right-mouse clicks?  
Avatar of traygreen
traygreen

Try this in the mouse down event for the controls in question...

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If Button = 2 And Shift = 0 Then
      Button = 0
      MsgBox "Mouse Down"
   End If

End Sub

or put the code in a global routine
Public sub SupressPopup(Button As Integer, Shift As Integer)
   If Button = 2 And Shift = 0 Then
      Button = 0
      MsgBox "Mouse Down"
   End If
end sub

and put ...
Call SupressPopup(Button, Shift) in the mousedown events

Avatar of craigdawson

ASKER

Popup menu still appears.
ASKER CERTIFIED SOLUTION
Avatar of traygreen
traygreen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, I should have been more clear.  It works as long as the msgbox is there but not once that line is removed.  I can't have message boxes popping up on every right-click so I still have no solution.
CraigDawson,
    What I've had to do in the past is create my own popup menu and use it in place of the default popup menu. It's usually just a bogus menu item (HELP, for example). To do this, create a menu item, we'll call it mnuTest for this example. Click off "visible", so that it doesn't show in your application. Then you must have at least one subitem, so create a menu item underneath mnuTest called mnuHelp. It must be visible (too bad, too, because that would solve our problem).

Then, in your TextBox MouseDown event, put this:

If Button = 2
    Text1.Enabled = False
    PopupMenu mnuTest
    Text1.Enabled = True
    Text1.SetFocus
End-if

Your new popupmenu will display instead of the default, and it won't have Paste. You'll obviously have to display the help file, or whatever bogus thing you did put on your menu, but it effectively prevents them from using the Paste command, and doesn't look bad. It's an alternative to preventing all right mouse clicks.