Changing ContextMenu

Posted on 2006-04-25
Last Modified: 2008-02-01
I want to attach to a form a different ContextMenu each time, depending on the region in the form that was right clicked.
Does a form raise an event just before it displays a ContextMenu? (In Delphi the form raises the ContextPopup event.)
Question by:libbysharf
    LVL 6

    Expert Comment

    The ContextMenu fires a Popup event which happens before the ContextMenu is actually displayed.

    Author Comment

    Thanks... But what if, as I said, I'm using several ContextMenus and switching betwwen them? Do I have to populate each one of them with the same event handler for popup? Wouldn't it be much less cumbersome if only the component they are attached to raise the event?
    Does anyone know if there is such event that the component raise?
    LVL 11

    Accepted Solution

    you could use the forms mouseup event and check for right mousebutton and show the specific context menu.
    private void Form1_MouseUp(object sender, MouseEventArgs e)
                if (e.Button == MouseButtons.Right)
                    //show specific context menu

    Author Comment

    The problem is that the user can also use the keyboard to popup the menu....
    Thanks anyway. vo1d, you get the points for the effort.
    LVL 11

    Expert Comment

    yes he can, but for that, you could use the keyup event and make a call of the mouseup eventhandler with the correct mouseventargs.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    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.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now