CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    27

    Tracking Source of Context Menu

    I have a form which 30 some labels exist. Each Label has the same context menu binded to it. I would like the ability to retrieve & pass the label that activated the context menu's click event, to a specified function.

    Now the click event does have the sender object, however it's getType shows it as a menu control. Manually, using add watch during debugger, I can sort through sender and find the initiating label. So the question is, is there some way of taken the sender object and retrieving the initiating label through code?

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: Tracking Source of Context Menu

    Dim snd as MenuItem = DirectCast(sender, MenuItem)
    Dim Lbl as Label = DirectCast(snd.GetContextMenu.SourceControl, Label)

    MessageBox.Show("The label was " & lbl.Name)

  3. #3
    Join Date
    Jul 2005
    Posts
    27

    Re: Tracking Source of Context Menu

    Thanx, works great

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

Featured