Changing a button's color via script

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
David L
Posts: 2
Joined: Thu May 03, 2012 9:53 am

Changing a button's color via script

Post 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?

David L
Posts: 2
Joined: Thu May 03, 2012 9:53 am

Re: Changing a button's color via script

Post 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?

User avatar
Ron L.
Posts: 214
Joined: Fri Jul 15, 2011 3:21 pm

Re: Changing a button's color via script

Post 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.
Best Regards,

Beijer Electronics, Inc.
Ron Lloyd | Applications Engineer

JStephenson
Posts: 2
Joined: Mon Dec 14, 2015 2:27 pm

Re: Changing a button's color via script

Post 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.

Post Reply