Collapse event in C# ContextMenu does not work as expected.

I am trying to change the state of my application according to whether or not a ContextMenu is being displayed.

-----
ContextMenu menu = new ContextMenu();
...
menu.Popup += new EventHandler( doSomething );
menu.Collapse += new EventHandler( doSomethingElse );
...
menu.Show(this, new Point(e.X, e.Y));
-----

doSomething gets called as expected whenever a menu is shown but doSomethingElse is never called. I also tried to subclass ContextMenu and override the popup and collapse methods themselves. Again, the popup method worked but the collapse one was never called.

Are my expectations faulty or is it the code?
rosenavAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Priest04Commented:
May I ask why don't you use ContectMenuStrip class (since ContextMenu class is obsolete). Since you are using collapse event, this method didnt exist prior to framework 2.0, so there in no point in not using ContextMenuStrip.

Goran
0
rosenavAuthor Commented:
So I should just accept that the C# library is incomplete and rewrite my context menus?
0
Priest04Commented:
So, you are converting your 1.x application to 2.x (or 3.x)? I thought you are making a new project. Anyway, I would recommend rewriting it, if there isn't much work to do. If not, then all you can do is next:

Do not call Show method, Collapse method doesn't work with it. Instead, assign ContextMenu instance to a control. Example


this.ContextMenu = contextMenu1; // this will show context menu when you right-click on a form, and it will call Collapse event when closing it.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rosenavAuthor Commented:
Thanks for your help. I think I'll have to rewrite with ContextMenuStrip when I get a chance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.