Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

My problem is that I have a contextmenustrip that is used by multiple buttons on a form and the contextmenustrip has contextmenustripitems, that call methods that customize the look of a button, for instance the font, fore and back colour.

The problem being is that I am trying to get the button that the contextmenustrip has been called on. The reason for this is so that I can then apply the colour or new font to the button that has had the contextmenustrip opened on, by supplying the current button the method that will make these changes, as an argument.

I don't really know how I would go about doing this so any help is much appreciated :)
Posted
Updated 14-Nov-21 17:25pm
v3

You can determine this from the SourceSource control property of the Context menu during the opening event.

This is the VB.net code, haven't checked for the C# equiv.

VB.NET
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

    Debug.WriteLine(ContextMenuStrip1.SourceControl.ToString)

End Sub
 
Share this answer
 
v2
```
Dim ControlsName as string 
Private Sub ContextMenuStrip1_Opening(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening

        ControlsName= ContextMenuStrip1.SourceControl.Name.ToString

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900