Link to home
Start Free TrialLog in
Avatar of jbajaj
jbajaj

asked on

click required to exit a context menu

Hello

Design :
I have two buttons. Everytime I move my mouse over their reigion ( mouseenter event) , a context menu pops up . Each button has a different context menu .

problem scenario:
Move mouse over button1 , context menu pops up. Now when I move to button2 the mouseevent for that button wont trigger unless or until I click on the previous context menu selction or Click somewhere outside i.e a click event is required for me to close the context menu. I want to change this to mouseenter or something which would prevent the above

Please let me know asap. I dont want to use a usercontrol

Thanks
Avatar of jbajaj
jbajaj

ASKER

So I want a way in which my mouseevent can trigger once I have left the context menu
Avatar of AndyAinscow
<I dont want to use a usercontrol>

I think you are left with writing a mouse hook  BUT consider.
Menu appears, user moves mouse a little off menu in process of selecting the desired action and menu disappears.  It could prove to be annoying behaviour to the user.  (And you have to make sure that the mouse is actually over the menu when it appears else the user can't use the mouse to make a selection).
Avatar of jbajaj

ASKER

Well then how is the menu in start of XP implemented

When I move the cursor over PROGRAMS, the menu pops up and  then move the cursor over  DOCUMENTS and anotehr menu pops up.

In my case, moving the mouse over  DOCUMENTS does not trigger any mouse events  
That is standard menu behaviour when there is a child menu at the mouse position.

Win XP - mouse over programs and a sub menu appears, move mouse away (off menu completely) and sub menu stays visible.
Avatar of jbajaj

ASKER

This does not answer my question .

I have two buttons associated with 2 different context menus. When one pops up and I move the mouse to the other button., I want the previous context menu toclose and the new context menu to show

Please help
 
Avatar of jbajaj

ASKER

Ok if the above cannot be resolved or is a bit complicated

Here is what might be more helpful for me

Can I have a main menu embedded in my tabpage , on the left side of the tabpage

I guess then I dont need to worry about the above . Also how do I then change the color of the main menu

thank you
Jayesh
Unfortunately AFAIK changing the background colour of a menu isn't trivial either.

My thoughts at this point is that the simplest way would be to create your own control - which you said you didn't want.
Avatar of jbajaj

ASKER

Thanks for the quick responses

I managed to change the color of the context menu . Would it be similar ?
Can we align the main menu to the left of the tabpage?
I dont mind writing my owncontrol, but dont know how to ?

Please let me know asap. Would be highly appreciated
Avatar of jbajaj

ASKER

Hello , so i have options here

1.> have a main menu implemented on the left side of the tabpage and have it work like thePROGRAMS , DOCUMENTS etc menu in windows. If I need to add my own control, please send me the code how to do so

OR

2.> Have a mouse hook in such a way that when I move my mouse over button2, the context menu opened by button1 closes and the context menu associated with button2 opens. Currently the mouseenter evnt on moving the mouse over button2 doesnt fire when the context menu associated with button1 is opened. I need to 'click'

Please help asap

Thank you
 
Avatar of jbajaj

ASKER

Helloo, could someone please provide me some code for option 2
Avatar of jbajaj

ASKER

Well,

I want a way to hide the popup menu ( context menu) when I move my mouse over a button , and not on left click

Please help

thank you
Avatar of jbajaj

ASKER

Hello

I saw a discussion for this on
https://www.experts-exchange.com/questions/20990107/Hide-a-context-menu.html?query=hiding+context+menu&clearTAFilter=true

But this 2 doesnt give me the answer. lease provide me the code to so

Thank you
I am in a different time zone to you, I've not been neglecting this.
Avatar of jbajaj

ASKER

Oh, I never meant that way :)...I was just updating my finding to make things more clear. I am new to VB.net
<Currently the mouseenter evnt on moving the mouse over button2 doesnt fire when the context menu associated with button1 is opened. I need to 'click'>

I think that the menu has 'captured' the mouse - hence the need for a hook to see any mouse messages.  Have a look at
https://www.experts-exchange.com/questions/10040679/Capturing-mouse-position.html
which may help.


Also the DestroyMenu and GetSafeHMenu functions of CMenu will probably be required for you to test if a menu exists and to destroy it.  You will need the CMenu to be a member variable of the class, not a local variable in the mouseover event handler
Avatar of jbajaj

ASKER

Can you please send me a sample application doing this. I am unable to follow this...Thanks
<Can you please send me a sample application doing this. >
No.  I get paid to write code, here I will give advice and comments.  Also it is better for you in the end to learn how to do it, just copying a piece of code doesn't make one understand the techniques.

Exactly what bit is giving you a problem?
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbajaj

ASKER

OK here you go... I have 2 buttons index_futures and index_options...and here is the code I am trying
index_futures_cm and index_options_cm are the two context menus assocaited with them


  Private Sub index_futures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_futures.MouseEnter

        index_futures.BackColor = Color.DarkBlue
        index_futures.ForeColor = Color.White

        index_options.BackColor = Color.WhiteSmoke
        index_options.ForeColor = Color.Black

        pos = New Point(index_futures.Width + 1)
        index_futures_cm.Show(index_futures, pos)
        '  index_futures.BackColor = Color.DarkBlue
        ' index_futures.ForeColor = Color.White


    End Sub

 Private Sub index_options_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles index_options.MouseEnter

        index_options.BackColor = Color.DarkBlue
        index_options.ForeColor = Color.White

        index_futures.BackColor = Color.WhiteSmoke
        index_futures.ForeColor = Color.Black

        pos = New Point(index_options.Width + 1)
        index_options_cm.Show(index_options, pos)


    End Sub

Now can you please give me pointers based on the above code....where do i add events . I am totally confused ????