Dabas
asked on
Hide a context menu
When right clicking a button, I create a context menu dynamically, filling its values from a dataset
The program works fine, that is not the problem.
What happens if the user does not want to choose any of the values and wants the menu to "hide" itself from view?
Currently the user has to click elsewhere to achieve this effect.
I have been asked to accomplish this whenever the mouse leaves the context menu's area.
1) Can this be done? (There is no MouseLeave event for the context menu control)
2) How?
This is my code to create the menu:
Private Sub btnMenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs)
Try
If e.Button = MouseButtons.Right Then
Dim mnu As New ContextMenu
For Each dr As DataRow In dsValues.Tables(0).Rows
Dim mi As New MenuItem
mi.Text = dr.Item("Symbol").ToString
mnu.MenuItems.Add(mi)
AddHandler mi.Click, AddressOf ProcessMenuItem
Next
mnu.Show(CType(sender, Control), New Point(-20, -20))
End If
Catch ex As Exception
GeneralErrors(ex)
End Try
End Sub
The program works fine, that is not the problem.
What happens if the user does not want to choose any of the values and wants the menu to "hide" itself from view?
Currently the user has to click elsewhere to achieve this effect.
I have been asked to accomplish this whenever the mouse leaves the context menu's area.
1) Can this be done? (There is no MouseLeave event for the context menu control)
2) How?
This is my code to create the menu:
Private Sub btnMenu_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
Try
If e.Button = MouseButtons.Right Then
Dim mnu As New ContextMenu
For Each dr As DataRow In dsValues.Tables(0).Rows
Dim mi As New MenuItem
mi.Text = dr.Item("Symbol").ToString
mnu.MenuItems.Add(mi)
AddHandler mi.Click, AddressOf ProcessMenuItem
Next
mnu.Show(CType(sender, Control), New Point(-20, -20))
End If
Catch ex As Exception
GeneralErrors(ex)
End Try
End Sub
ASKER
Greg:
Thanks for your reply!
> by watching where the mouse is on the screen
Tried that. I do not seem to get any mouse events to trigger while the menu is up.
Dabas
Thanks for your reply!
> by watching where the mouse is on the screen
Tried that. I do not seem to get any mouse events to trigger while the menu is up.
Dabas
I mean watch global events via API
ASKER
UGH! I don't like to use API calls, LOL!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
what about using timers and closing the contextmenu after a time interval
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
SendKeys.Send("{ESC}")
timer1.Stop()
End Sub
Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs)
'set interval to 5 seconds
timer1.Interval = 5000
timer1.Start()
End Sub
Regards,
Venki
what about using timers and closing the contextmenu after a time interval
Private Sub timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
SendKeys.Send("{ESC}")
timer1.Stop()
End Sub
Private Sub contextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs)
'set interval to 5 seconds
timer1.Interval = 5000
timer1.Start()
End Sub
Regards,
Venki
ASKER
Venki:
Thanks for the idea!
Not really what I am after, though.
This might be quite frustrating to the user when he moves the arrow away from the menu on second two and does not understand why it suddenly dissappears a full three seconds later when he was about to do something else. Or alternatively, a user who is hesitating and just as he is about to click on an option, the whole thing dissappears!
Dabas
Thanks for the idea!
Not really what I am after, though.
This might be quite frustrating to the user when he moves the arrow away from the menu on second two and does not understand why it suddenly dissappears a full three seconds later when he was about to do something else. Or alternatively, a user who is hesitating and just as he is about to click on an option, the whole thing dissappears!
Dabas
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Bob.
Yours and Greg's opinion only reinforced whatever I thought to start with, but I was asked to "- When right click a button to get pull down ..if move mouse away, then get rid of pull down.", and did not want to go back with "This is too much trouble for something nobody will be using anyway!", without checking that this is really the case.
Dabas
Yours and Greg's opinion only reinforced whatever I thought to start with, but I was asked to "- When right click a button to get pull down ..if move mouse away, then get rid of pull down.", and did not want to go back with "This is too much trouble for something nobody will be using anyway!", without checking that this is really the case.
Dabas
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp should explain scripting in .net ...
oops
If the user slips a bit especially with sub menus it would kind of suck to have the menus disappear. I'm sure there is a way you could work around it by watching where the mouse is on the screen and forcing it to close but you would then be leaving a standard windows interface.