Page 1 of 1

Changing a button's color via script

Posted: Mon May 14, 2012 9:53 am
by David L
I may be missing something obvious here, but I am trying to change a button's color via script. I thought I had successfully done this before, but I can't seem to recreate it.

I have a button called Button1, and I have Button1_Click hooked into it. Inside Button1 I have two lines of code:

Code: Select all

Button1.Text = "Button Pressed";
Button1.Fill = new BrushCF(Color.Blue);
The text is changing, but the color of the button does not change. Any suggestions on how I can do this?

Re: Changing a button's color via script

Posted: Mon May 14, 2012 10:01 am
by David L
After trying for over an hour yesterday, I finally figured it out about 5 minutes after posting my question. I had applied a Style to the button, which meant that it no longer responded to the Script to change the color. When changing from Classic back to Default, I can change the color.

That leads me to my modified question: Is there a way to keep the Style while still being able to change the color at run-time?

Re: Changing a button's color via script

Posted: Mon May 14, 2012 10:31 am
by Ron L.
There's not a way to do that. The best you can do is have multiple buttons with different styles and change there visibility at run-time.

Re: Changing a button's color via script

Posted: Mon Dec 14, 2015 2:31 pm
by JStephenson
Has a solution to this problem been implemented since 2012? Im running into this issue as well, and really need to keep the non standard button styling while maintaining the ability to change background color.

Is there a better simple way to change a button's background color when pressed? I just need it to maintain a latched state when pressed, with a different color.