1.1k views
in Getting started by
Hello,

I'd like to change the color of my background every time a user clicks on a button. I was thinking about incrementing an int variable and then creating a new "color string" from this variable.

However, I haven't found any way to convert a string to a color type?!

Thanks.

1 Answer

0 votes
by

Hello,

maybe it is a little bit complexified if you convert an integer into a string and then convert the string into a color.

Let the integer represent the currently selected color number and then just assign the background color according to the currently selected color number:

if ( ColorNumber == 0 )
  Rectangle.Color = #000000FF; // black
else if ( ColorNumber == 1 ) 
  Rectangle.Color = #FF0000FF; // red
else if ( ColorNumber == 2 ) 
  Rectangle.Color = #00FF00FF; // green
else if ( ColorNumber == 3 ) 
  Rectangle.Color = #0000FFFF; // blue
else
  Rectangle.Color = #FFFFFFFF; // white

Does this help?

Best regards,

Manfred.

by
This is a non-solution to me… What am I supposed to do if the user wants to click 250 times on the button ?!
by

In order to make good proposals it is always helpful to understand the entire use-case...

You can create your colors dynamically based on integers by using the color instant constructor.

Does this help?

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...