Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multicolored label
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00700941
Message ID:
00701627
Views:
14
Tim,

>I was looking for an idea how to create a class or method to parse a label's chars and have each one a different color, if at all possible.

Let me propose a much simpler solution using some little used form methods:
dodefault()

if ( empty( this.Tag ) )
   this.CurrentX = this.Label1.Left
   this.CurrentY = this.Label1.Top

   for i = 1 to len( this.Label1.Caption )
      this.ForeColor = rgb( rand() * 255, rand() * 255, rand() * 255 )
      this.Print( substr( this.Label1.Caption, i, 1 ) )
   endfor
endif

this.Tag = "first activation done"
put this code in the Activate() instead of Init() because the form has to be visible and the initial painting of the label would going to overwrite the this.Paint() output. You can control it with a real boolean property I've just hacked it with tag for demo.

You can create a label class that lets you embed color change commands inside the Tag or custom property and use them to set the forecolor property instead. Something like:

"This <0xFF0000>is red now it's black"

Or come up with some other scheme where you can set the Caption to the real text value you want displayed and this will let you position the label and controls correctly at design time and read the color changes from a separate property.

This is a lot lighterweight than adding additional label letters and it allows you to keep stuff like Click() methods of the label intact.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform