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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Width of label 3

Status
Not open for further replies.

jimstarr

Programmer
Feb 6, 2001
975
US
I have a label with AUTOSIZE = .T. which can be assigned many different captions at runtime. How can I determine the width of the label after assigning a new caption? The WIDTH property doesn't seem to change.

Thanks in advance.


Jim
 
Jim

This is untested as it's pulled from some other code
Code:
lcLine = .lblLabel1.Caption
lnWidth	= (TXTWIDTH(&lcLine,[MS Sans Serif],8)	*	;
			FONTMETRIC(6,[MS Sans Serif],8))
Hope you get the idea

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Jim,

This is the method I use:

Code:
FUNCTION GetTextSize

* Determines the width in pixels of a given text string, based on 
* a given font, font style and point size.

* Parameters: text string, font name, size in points, font style in
* format used by FONTMETRIC() (e.g. "B" for bold, "BI" for bold italic;
* defaults to normal).	

LPARAMETERS tcString, tcFont, tnSize, tcStyle

LOCAL lnTextWidth, lnAvCharWidth

IF EMPTY(tcStyle)
	tcStyle = ""
ENDIF 
	
lnTextWidth = TXTWIDTH(tcString, tcFont, tnSize, tcStyle)
lnAvCharWidth = FONTMETRIC(6, tcFont, tnSize, tcStyle)

RETURN lnTextWidth * lnAvCharWidth

ENDFUNC

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top