Controls Sharing a Context Menu

  • Thread starter Thread starter jcrouse
  • Start date Start date
J

jcrouse

Is it possible more multiple controls (labels) to share the code from one
context menu. I have 32 labels on a form and don't want to add 32 context
menu controls. Where might I find information on how to do this if possible?

Thanks,
John
 
you can add just one event handler that handles the mouseup event for all
your labels:

Private Sub AllLabels_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
Label1.MouseUp, Label2.MouseUp, Label3.MouseUp
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(CType(sender, Control), New Point(e.X, e.Y))
End If
End Sub

basically, you add and setup just one context menu (here ContextMenu1) which
you probably already did. As in the code above, you add only one event
handler to handle the mouseup events for all your labels (here Label1,
Label2 and Label3). the rest is self-explanatory.
hope this helps..post back if you have any questions or if this does not
make sense..
imran.
 
Back
Top