bunifu Button Color Change on Click

29 Views Asked by At

while trying to change button color or border color on click with code below:

      private void LoggerStart_Click(object sender, EventArgs e)
        {
            if (LoggerStart.Text == "Start")
            {
                //?
                LoggerStart.Text = "Stop";
                LoggerStart.IdleBorderColor = Color.Red;
            }
            else
            {
                LoggerStart.Text = "Start";
            }
        }

the color changes for a short time, and returns to it's default color instantly!.

I expected to get the new color but it gets back to default shortly!

2

There are 2 best solutions below

0
Classic_Fungus On

Try to use other comparsion, ex. based on buttons color/border color

private void button1_Click(object sender, EventArgs e)
    {
        if (button1.ForeColor != Color.Green)
        {
            button1.ForeColor = Color.Green;
            button1.Text = "stop";
        }
        else
        {
            button1.ForeColor = Color.Red;
            button1.Text = "start";
        }
    }
1
Sedna.Kianfarooghi On

I used LoggerStart.Idlefillcolor and it solved my problem.