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

Posted on 2008-11-05
Last Modified: 2012-08-13
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?
Question by:rosenav
    LVL 18

    Expert Comment

    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.


    Author Comment

    So I should just accept that the C# library is incomplete and rewrite my context menus?
    LVL 18

    Accepted Solution

    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


    Author Closing Comment

    Thanks for your help. I think I'll have to rewrite with ContextMenuStrip when I get a chance.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now