Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Determine where contect menu was called from

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    30

    Resolved [RESOLVED] [2008] Determine where contect menu was called from

    It seems to me that there should be a simple way to determine which control the user right-clicked to bring up the context menu.

    I have several identical controls on a form that display different data, but the context menu options are the same for each control. I'd much prefer to create just one context menu with associated code, rather than duplicate that stuff for each control on my form.

    Obviously, to do that I must be able to tell which control was right-clicked on so that I can tailor the menu item's response to that control.

    Does anybody have any ideas on how this is accomplished? I thought the answer might be in the sender parameter that is passed to the menu item handler, but that only tells me which menu item was selected.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Determine where contect menu was called from

    It seems to me that there should be a simple way to determine which control the user right-clicked to bring up the context menu.
    That seems reasonable. It's also reasonable that, if there is a way they'd have mentioned it in the documentation. Reading the documentation for the ContextMenuStrip class we find the SourceControl property, which is is described as:
    Gets the last control that caused this ContextMenuStrip to be displayed.
    I'd suggest making a point of reading the documentation first in future.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2008
    Posts
    30

    Re: [2008] Determine where contect menu was called from

    Actually, I did read the documentation, but I seemed to have missed that property

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Thumbs up Re: [RESOLVED] [2008] Determine where contect menu was called from

    I was looking to find which control was invoking an event as well, and i didn't find it either, so don't feel bad. Looking back now, i'm not sure how i missed it.
    .
    ~Peter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width