Question

my Program has many buttons. i like to use "1" contextmenustrip when i right click on a button you get a options like "change color red". my problem is that i dont know how to code this for all the button.

    private void changeColorToolStripMenuItem_Click(object sender, EventArgs e)
{
    btn1.BackColor = Color .Red;
}

now i can change the color for 1 button but if i need this to do with all the buttons it takes a long time and i need to use more than 1 contextmenustrip. so i need to change the color from the button that you right click.

i am sorry for my bad english if it is not clear i will try to explain it again. thanks

Était-ce utile?

La solution

You can use the SourceControl() property of the main ContextMenuStrip to determine which button was the source of the event:

    private void changeColorToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Control ctl = contextMenuStrip1.SourceControl;
        ctl.BackColor = Color.Red;
    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top