How to dynamically change a button's background color?

Hi rooters,

I have a GUI program in which I want to change a button’s background color dynamically. I 'm trying to do this in the following way.

if ( condition ) {
button->SetBackgroundColor( color1 );
}
else {
button->SetBackgroundColor( color2 );
}

But I found the button’s color was not changed immediately. Did I miss something? Is there some way to redraw a button individually? Or I have to notify the main window to redraw everything? If so, how to do that?

Haibing ZHANG

Hi,

Try this way:

if ( condition ) { button->ChangeBackground( color1 ); } else { button->ChangeBackground( color2 ); }or:if ( condition ) { button->SetBackgroundColor( color1 ); } else { button->SetBackgroundColor( color2 ); } gClient->NeedRedraw(button);
Hope this helps.
Cheers, Bertrand.

Hi Bertrand,

It works. Thanks a lot.

Haibing

You’re most welcome!
Cheers, Bertrand.