title: contextmenustrip opening event determining sender
body: <p>I have 30 labels. They can have any value I want.
  I need to be able to assign one context menu to them all then determine which label was clicked in order to use my <code>x</code>    variable.</p>
  <pre><code>    Private Sub Label_Click(sender As Object, e As MouseEventArgs) Handles       Label1.MouseClick, Label2.MouseClick, Label3.MouseClick, Label4.MouseClick, _
      Label5.MouseClick, Label6.MouseClick, Label7.MouseClick, Label8.MouseClick, Label9.MouseClick, Label10.MouseClick, Label11.MouseClick, _
      Label12.MouseClick, Label13.MouseClick, Label14.MouseClick, Label15.MouseClick, Label15.MouseClick, Label16.MouseClick, Label17.MouseClick, _
      Label18.MouseClick, Label19.MouseClick, Label20.MouseClick, Label21.MouseClick, Label22.MouseClick, Label23.MouseClick, Label24.MouseClick, _
      Label25.MouseClick, Label26.MouseClick, Label27.MouseClick, Label28.MouseClick, Label29.MouseClick, Label30.MouseClick
      
     Dim x As String = sender.Text
     xmlinteraction.appCall(x)
      End Sub
  </code></pre>
  <p>I received awesome help the other day <a href="https://stackoverflow.com/questions/18370545/passing-variable-into-contextmenustrip">passing variable into contextmenustrip</a>
  But I am too new to put it all together and make it work. I understand what we are trying to do, but not all the syntax. Please help.</p>
  <hr />
  <p>Jay,
  Here is what I put together from the code you gave me. Is this what you were thinking? I feel like I missing something still and further clean the code. Possibly removing the case statements.</p>
  <pre><code>   Private Sub rcmenuOption(x, y)
          ' x is equal to what the menu item was clicked
          ' Create case stament for that to call the correct xmlinteraction passing in y
          Select Case x
              Case &quot;Copy Link&quot;
                  copyClipboard(y)
          End Select
      End Sub
      Private Sub rcmenuClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles rcmenu.ItemClicked
          ' Get the Label clicked from the SourceControl property of the clicked ContextMenuStrip.
          Dim contextMenu = DirectCast(sender, ContextMenuStrip)
          Dim label = DirectCast(contextMenu.SourceControl, Label)
          Dim var2 As String = label.Text
          ' Get the clicked menu strip and update its Text to the Label's Text.
          Dim toolStripItem = e.ClickedItem
          Dim var As String = toolStripItem.Text
          rcmenuOption(var, var2)
      End Sub
  </code></pre>
  <p><a href="https://stackoverflow.com/questions/18415128/contextmenustrip-opening-event-determining-sender">contextmenustrip opening event determining sender</a></p>