|
-
Jul 11th, 2008, 08:44 AM
#1
Thread Starter
Hyperactive Member
Dismiss a PopuMenu in code?
When moving a pointer over a control I'm invoking a hidden "What's this?" PopupMenu to give user a help on that functionality.
The control has MouseEnter and MouseLeave events so I show the popup in MouseEnter, but I'd like to remove the menu in MouseLeave if user doesn't click on the menu.
Can I remove PopupMenu without clicking on it?
-
Jul 11th, 2008, 11:12 AM
#2
Re: Dismiss a PopuMenu in code?
Doesn't it go away if the user clicks on anything else other than the popup menu? That's the default behavor of a popup menu.
-
Jul 11th, 2008, 11:35 AM
#3
Re: Dismiss a PopuMenu in code?
-
Jul 11th, 2008, 11:56 AM
#4
Re: Dismiss a PopuMenu in code?
Hack,
Not to attempt to draw away from his post but what causes a popup menu to not go away by clicking elsewhere? I have never had that problem.
-
Jul 11th, 2008, 12:41 PM
#5
Re: Dismiss a PopuMenu in code?
The popup menu will go away if you click anywhere else on the form...but I think that is his point. I'm assuming he wants the menu to go away when the mouse leave the control without having to click anywhere.
-
Jul 11th, 2008, 12:53 PM
#6
Re: Dismiss a PopuMenu in code?
 Originally Posted by MarkT
The popup menu will go away if you click anywhere else on the form...but I think that is his point. I'm assuming he wants the menu to go away when the mouse leave the control without having to click anywhere.
Correct, and correct.....
I use the code in the link I posted with popup menus from my programs that are running in the system tray, so I'm guessing that might work with his as well.
-
Jul 11th, 2008, 01:35 PM
#7
Thread Starter
Hyperactive Member
Re: Dismiss a PopupMenu in code?
Hi Guys,
I'm back.
MarkT is right, I'd like to move the mouse over a control, see popup menu, then move away and for menu to dissapear.
Hack, I tried the SetForegroundWindow() but didn't work for me
I also tried EndMenu() same result.
BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.
When the user actually does click the menu, I'm showing a help form.
-
Jul 11th, 2008, 01:46 PM
#8
Re: Dismiss a PopupMenu in code?
 Originally Posted by Tomexx
BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.
That would explain why it didn't work for you.
I was testing on a standard VB command button (and you can code the mouse enter/mouse leave with a couple of API calls.)
I'll take a look at his XPButtons and see if I can come up with something.
-
Jul 11th, 2008, 01:50 PM
#9
Thread Starter
Hyperactive Member
Re: Dismiss a PopuMenu in code?
Thanks Hack,
Can you also show me how to code those MouseEnter & MouseLeave events for use with standard buttons?
-
Jul 11th, 2008, 01:53 PM
#10
Re: Dismiss a PopuMenu in code?
I suspect Woka's buttons are a lot cooler looking so I wouldn't swap everything out just yet. I'm sure there is a way to get this done using what you currently have. Like I said, I'll take a look and see if I can come up with anything.
This is for future reference.
Code:
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X < 0) Or (Y < 0) Or (X > Command1.Width) Or (Y > Command1.Height) Then
ReleaseCapture
'the mouse is no longer over the button, so do whatever
ElseIf GetCapture() <> Command1.hwnd Then
SetCapture Command1.hwnd
'the mouse is over the button, so do whatever
End If
End Sub
-
Jul 14th, 2008, 11:29 AM
#11
Re: Dismiss a PopupMenu in code?
 Originally Posted by Tomexx
Hack, I tried the SetForegroundWindow() but didn't work for me
I also tried EndMenu() same result.
BTW, I'm using Woka's vbXPbuttons. They have MouseEnter & MouseLeave, so I call the PopumMenu in MouseEnter and I wanted to hide the menu in MouseLeave.
I'm not familiar with Woka's vbXPbuttons but I just had a similar problem where I use subclassing to detect the mouse buttons and found that PopupMenus don't close when clicking the Forward or Back mouse buttons, so to solve that I just set the parent's .Enabled property to False then set it right back to True and the PopupMenu closes!
Code:
Public Sub ClosePopUpMenu()
' Called from hook - forward/back mouse buttons.
If MnuSave.Visible = True Then ' check one of the visible menu options.
Me.Enabled = False
Me.Enabled = True
End If
End Sub
If vbXPbuttons mouseleave event does not fire when a PopupMenu is visible then I'd guess you'd have to subclass or use a timer to track the mouse cursor position
.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|