Board index » Visual Studio » Using Right click keep menu from poping up

Using Right click keep menu from poping up

Visual Studio337
Can someone tell me how disable the popup menu when you right click in a

text field.



Thanks Mark


-
 

Re:Using Right click keep menu from poping up

Quote
Can someone tell me how disable the popup menu when you right

click in a text field.



If you are going to replace the popup menu with a popup menu of your own,

there is a simple kludge to suppress the one VB is throwing up

automatically. If you just want to stop it completely (without replacing

it), then the solution is more complex. Which are you attempting to do?



Rick



-

Re:Using Right click keep menu from poping up

Rick,



After thinking about it I could just put my function it the popup box so I

could do it either way.



Thanks Mark



"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in

message news:OVFNNA$lHHA.3928@TK2MSFTNGP02.phx.gbl...

Quote
>Can someone tell me how disable the popup menu when you right

>click in a text field.



If you are going to replace the popup menu with a popup menu of your own,

there is a simple kludge to suppress the one VB is throwing up

automatically. If you just want to stop it completely (without replacing

it), then the solution is more complex. Which are you attempting to do?



Rick





-

Re:Using Right click keep menu from poping up

Quote
>>Can someone tell me how disable the popup menu when you right

>>click in a text field.

>

>If you are going to replace the popup menu with a popup menu of your own,

>there is a simple kludge to suppress the one VB is throwing up

>automatically. If you just want to stop it completely (without replacing

>it), then the solution is more complex. Which are you attempting to do?



After thinking about it I could just put my function it the popup box so I

could do it either way.



Here is the kludge work-around for the problem (the only "downside",

assuming you consider it one, is that your popup menu occurs on pressing the

right-button down rather than the standard of waiting until the right button

is released). Start by creating a main Menu item (here I am assuming you

know how to create a Menu; if not, write back saying so) and set its Visible

property to False; then place the items you want to show on the popup menu

as sub-items under the main Menu item. Finally, add this code where

indicated in the comments.



' Put this in the form's (General)(Declaration) section

Private Declare Function ReleaseCapture Lib "user32" () As Long



' Use this MouseDown event code for your TextBox

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





Rick



-

Re:Using Right click keep menu from poping up



"Mark" <Mark@advancemicrosystems.com>wrote in message

Quote
"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in

message news:OVFNNA$lHHA.3928@TK2MSFTNGP02.phx.gbl...

>>Can someone tell me how disable the popup menu when you right

>>click in a text field.

>

>If you are going to replace the popup menu with a popup menu of your own,

>there is a simple kludge to suppress the one VB is throwing up

>automatically. If you just want to stop it completely (without replacing

>it), then the solution is more complex. Which are you attempting to do?

>

>Rick



Rick,



After thinking about it I could just put my function it the popup box so I

could do it either way.





Well, which would you PREFER? I only vaguely recall the kludge, but I'm

pretty sure it's just doing something like this (air code) in the textbox's

MouseUp event (perhaps you need to instead disable the textbox in MouseDown,

not sure about that):



If Button = vbRightButton Then

Text1.Enabled = False

PopupMenu MyPopupMenu

Text1.Enabled = True

End If



If you want to suppress the standard right-click menu and not show a menu of

your own, you need to subclass the textbox and eat the WM_CONTEXTMENU

message (and you could then also show your own popup menu if desired). This

is actually the "correct" way to replace the standard popup menu (IOW, the

non-kludgy way).



One word of warning: you should NOT eat the WM_RBUTTONUP message because the

popup menu can be shown by other means besides right-clicking in the textbox

(for example, the user presses the context-menu key on the keyboard).



If you search the VB newsgroups at google groups for WM_CONTEXTMENU, you

should find tons of example code.



--

Mike

Microsoft MVP Visual Basic





-

Re:Using Right click keep menu from poping up



"Rick Rothstein (MVP - VB)" <rickNOSPAMnews@NOSPAMcomcast.net>wrote in

message news:OBcQvBBmHHA.4032@TK2MSFTNGP02.phx.gbl...

Quote
Here is the kludge work-around for the problem (the only "downside",

assuming you consider it one, is that your popup menu occurs on pressing

the right-button down rather than the standard of waiting until the right

button is released).

' Put this in the form's (General)(Declaration) section

Private Declare Function ReleaseCapture Lib "user32" () As Long



' Use this MouseDown event code for your TextBox

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





I guess I was recalling a different kludge. <g>



I guess I'll have to test if mine works.....hold on...



Ugh! Need to put the code (my code) in MouseDown which has the additional

nasty (IMO) effect of temporarily disabling the textbox such that the user

sees it's become disabled. Caca. If you want to go the kludge route, use

Rick's (although I strongly recommend using the proper way of subclassing as

I described).





--

Mike

Microsoft MVP Visual Basic





-