logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 How to prevent the default context menu from coming up over the TextBox

Posted on
11/17/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
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

 


Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Felix Adams. Posted on 5/31/2006 2:20:59 PM
http://www.vbrad.com/source_contents.aspx
Forms and Form Handling, GUI Techniques
Another way of Overiding the Default Context Menu in a Text Box. (source)
==>
Check if the computer supports sound
????

#2. By admin. Posted on 5/31/2006 4:03:01 PM
Ouch. Will fix. Thanks a bunch.