Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionally Formatting Text On Label Form

Status
Not open for further replies.

xBaseDude

MIS
Jan 31, 2002
357
US
Gentlemen;

I'd like to know how to change the properties of a label textbox at runtime.

I'm looking to be able to change the font and font size on the fly during the printing of the labels.

I understand I probably need to write a udf() to do something like this.

FUNC txtformat

DO CASE
CASE LEN(text_str) <=25
*** USE THIS FONT
*** USE BIGGER FONT SIZE
CASE LEN(text_str) >25 .AND. LEN(text_str) <= 50
*** USE ANOTHER FONT
*** USE MEDIUM FONT SIZE
CASE LEN(text_str) >50 .AND. LEN(text_str) <= 75
*** USE ANOTHER FONT
*** USE SMALL FONT SIZE
ENDCASE

Is this possible?

Could I ask for a coding example to accomplish this?

TIA - Wayne


sig_jugler.gif
...all this and tap dancing too!
 
xBaseDude

Here is a sample, just copy it and run it in a program. Click on the text in the grid to see the text apprear in the label.
Code:
Public oForm
oForm =Createobject(&quot;form1&quot;)
oForm.AddObject(&quot;lable1&quot;,&quot;label1&quot;)
oForm.AddObject(&quot;grid1&quot;,&quot;grid1&quot;)
oForm.Show()
Define Class label1 As Label
	Visible = .T.
	Height =60
	Top = 20
	Left = 20
	Width = 300
	WordWrap=.T.
Enddefine
Define Class grid1 As Grid
	Procedure Init
	With This
		.column1.AddObject(&quot;edit1&quot;,&quot;edit1&quot;)
		.column1.Width = 250
		.column1.Sparse = .F.
		.column1.CurrentControl = &quot;EDIT1&quot;
	Endwith
Endproc
Visible = .T.
Height = 250
Width = 450
RowHeight = 40
RecordSource = &quot;mycursor&quot;
ColumnCount = 1
Top =100
Enddefine
Define Class edit1 As EditBox
	Visible = .T.
	Procedure Click
	Do Case
	Case Len(This.Value) <25
		Thisform.lable1.FontSize = 24
	Case Between(Len(This.Value),25,50)
		Thisform.lable1.FontSize = 14
	Case Between(Len(This.Value),50,75)
		Thisform.lable1.FontSize = 7
	Endcase
	Store This.Value To Thisform.lable1.Caption
	Thisform.Refresh
Endproc
Enddefine
Define Class form1 As Form
	Procedure Init
	Create Cursor myCursor (Comment m)
	Insert Into myCursor (Comment) Values (&quot;install Visual FoxPro&quot;)
	Insert Into myCursor (Comment) Values (&quot;You can install Visual FoxPro from CD-ROM or a &quot;)
	Insert Into myCursor (Comment) Values (&quot;You can install Visual FoxPro from CD-ROM or a network to a local hard drive. You cannot install Visual FoxPro to a mapped drive.&quot;)
	Go Top
Endproc
Width = 500
Height = 500
Enddefine




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike;

I'm looking to be able to change the font and font size on the fly during the printing of the labels.

Sorry for the mis communication. I understand exactly what you were thinking and why I should not have been vague.

Substitute REPORT FORM instead of label. (I was working with the LABEL wizard in generating printed labels.)

Regards - Wayne


sig_jugler.gif
...all this and tap dancing too!
 
xBaseDude

I saw &quot;label&quot; and I saw &quot;form&quot; in the title. Easy mistake. My suggestion is to use three labels one on top of another and use the PrintWhen expresion to count the LEN of the field. Sorry, no code for that (other the showiing how to create a report on-the-fly and hacking it by code to place a label with that appropriate font size, but that would be useless.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top