-1

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

leppie
  • 115,091
  • 17
  • 196
  • 297

1 Answers1

0

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;
    }
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40