Can't get button background color to change

Hi
I have a button of type SfButton, called AutoButton, and I want it to go green when the legend is "AUTO ON".
Here is my code:

        private void AutoButton_MouseClick(object sender, MouseEventArgs e)
        {
            if (AutoButton.Text == "AUTO OFF")
            {
                var confirmResult = MessageBox.Show("Auto Mode selected",
                                     "Please confirm",
                                     MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    AutoButton.Text = "AUTO ON";
                    AutoButton.BackColor = Color.Green;
                }
            }
            else
            {
                AutoButton.Text = "AUTO OFF";
                AutoButton.BackColor = Color.Silver;
            }

            AutoButton.Refresh();
        }

The text changes to "AUTO ON", but the button does not go green.


If I use a standard button, it works.  Here is the code for that:

        private void button1_MouseClick(object sender, MouseEventArgs e)
        {
            if (button1.Text == "AUTO OFF")
            {
                var confirmResult = MessageBox.Show("Auto Mode selected",
                                     "Please confirm",
                                     MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    button1.Text = "AUTO ON";
                    button1.BackColor = Color.Green;
                }
            }
            else
            {
                button1.Text = "AUTO OFF";
                button1.BackColor = Color.Silver;
            }

            button1.Refresh();
        }

....  why isn't the SfButton changing colour?

Any help would be gratefully received.

Thank you.



2 Replies 1 reply marked as answer

EM Elakkiya Muthukumarasamy Syncfusion Team March 12, 2021 12:34 PM UTC

Hi Joanne, 
  
Greetings from Syncfusion. 
  
We were able to observe the reported behavior " SFButton BackColor is not changed at runtime " and we too able to reproduce it. We have logged a report on this and the patch for this fix is estimated to be available on 1st   April 2021.  
  
You can track the status of this defect using following feedback link:  
  
  
Please let us know if you need any other assistance on this.  
  
Regards,  
Elakkiya 



VR Vijayalakshmi Roopkumar Syncfusion Team April 1, 2021 10:58 AM UTC

Hi Joanne, 

Thank you for your patience.
 
 
On further analyzing on the reported behavior, we could found that in SfButton when the control is focused, then the back color will be applied based on the FocusedBackColor property. The background color will be applied if the control is not in a focused state. Hence this reported behavior can be resolved by changing the FocusedBackColor property. 
 
 
sfButton1.Style.FocusedBackColor = Color.Green; 
 
 
Regards, 
Vijayalakshmi VR 


Marked as answer
Loader.
Up arrow icon