how can i change buttons colour when they click?
  • I have a 5 buttons in winform application when i press button first time its change color then i click 2nd time its comes in old color i want short method only i apply that methods its apply on every button how ?
  • 1 Comment sorted by
  • hi yo can try this for work with all button with one event handler.


    private void Form2_Load(object sender, EventArgs e)
    {
    this.button1.Click += new System.EventHandler(this.button1_Click);
    this.button2.Click += new System.EventHandler(this.button1_Click);
    this.button3.Click += new System.EventHandler(this.button1_Click);
    this.button4.Click += new System.EventHandler(this.button1_Click);
    this.button5.Click += new System.EventHandler(this.button1_Click);
    }

    private void button1_Click(object sender, EventArgs e)
    {
    ChangeButtonColor((Button)sender);
    }

    private void ChangeButtonColor(Button btn)
    {
    if (btn.BackColor == Color.Red)
    {
    btn.BackColor = Color.Green;
    }
    else
    {
    btn.BackColor = Color.Red;
    }
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative