Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

closing a PopUp menu programatically

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
What-ho!

A round of golf applause (two fingers clapped against the opposite palm) to whom-so-ever can tell me how to cancel or otherwise close a PopUp menu through code (ie, not by clicking the mouse...I've figured that way out already).

I'm using the mouse_up event (right button) to invoke the PopUp menu, but I want to use the mouse_down event (right button) to cancel it, so that a new PopUp menu will be invoked wherever the mouse is when the right button is clicked, regardless of whether there's already a PopUp menu visible.

Easy or not easy?


Cheerio,

Paul
 
You can use SendKeys method to cancel the popup menu. In fact it is the same as pressing any key.

To see its effect, activate a popup menu using PopupMenu, then place a timer on the form and in Timer event, place this command:

SendKeys "{ESC}"

This will deactivate the menu, it looks as if you had pressed Escape key. (Just note that the form the popup menu is shown on, should have the focus. If not, use Show method to activate it first.

VB is very flexible, and you don't have to be worried if you don't want to give the focus to this form. If so, you can use ActiveForm property of Screen object to hold a reference to the currently active form, and then set the focus back to this form after you have set the focus to the form that had the popup menu shown on it.

I hope it helps :)
 
Hiya,

OK, that's good... I'm loathe to go picking holes here, as I appreciate your help, but I want the closing of the popup menu to be user event driven. I've actually found that the basic functionality of what I want to do can be achieved by using the vbPopupMenuRightButton flag on the PopUpMenu method, however, it's not perfect. This will effectively move the menu to where the mouse is next right clicked, but it doesn't take into account what it was clicked over (other than the control). So....what user events are available to me whilst a PopUp menu is being shown?

Cheerio,


Paul [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top