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:
00700962
Views:
8
>>A Method could parse the label and make each individual character a separate label with its own BackColor/Forecolor, sized to fit the single letter....lots of detail here but it should work...
>>
>>
>>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.
>
>So the idea is to have a regular label in place when the form opens then tinker with it when form opens. But how do you reference/parse a label's chars?

This sample is created just for fun. :)
PUBLIC f1
f1 = CREATEOBJECT("form1")
f1.SHOW()
****************************************
DEFINE CLASS form1 AS FORM


	TOP = 0
	LEFT = 0
	DOCREATE = .T.
	CAPTION = "Form1"
	NAME = "Form1"


	ADD OBJECT container1 AS CONTAINER WITH ;
		TOP = 48, ;
		LEFT = 60, ;
		WIDTH = 156, ;
		HEIGHT = 37, ;
		NAME = "Container1"


	PROCEDURE container1.INIT
		THIS.TAG = "abrakadabra"
		THIS.BORDERWIDTH = 0

		THIS.TAG = ALLTRIM(THIS.TAG)
		lnPieces = LEN(THIS.TAG)
		LOCAL ARRAY acolors[lnPieces]

		* Use whatever way to fill the colors array
		RAND(-1)
		FOR N = 1 TO lnPieces
			acolors[n] = RAND() * 100000
		ENDFOR
		*******


		LOCAL ARRAY aletters[1]
		* or you can use one array for letters/colors

		DIMENSION aletters(lnPieces)
		lnLeft = 0
		FOR N = 1 TO lnPieces
			aletters(N) = SUBSTR(THIS.TAG, N, 1)
			lcLabel = "label" + ALLTR(STR(N))
			THIS.ADDOBJECT(lcLabel, "label")
			
			WITH THIS.&lcLabel.
				.CAPTION = aletters(N)
				.AUTOSIZE = .T.
				.VISIBLE = .T.
				.FORECOLOR = acolors[n]
				.LEFT = lnLeft
				lnLeft = lnLeft + .WIDTH
			ENDWITH
			
		ENDFOR
		THIS.WIDTH = lnLeft
		THIS.HEIGHT = THIS.&lcLabel..HEIGHT
	ENDPROC


ENDDEFINE
*
**************************************************
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Reply
Map
View

Click here to load this message in the networking platform