PxLenght of Text in String/TextGadget
PxLenght of Text in String/TextGadget
Hi,
is there a way to determine the length (in pixels- not characters) of a text to be displayed in a StringGadget or TextGadget?
I want to display text of varying lengths in deactivated StringGadgets. Long Texts should be displayed in MultiLine Gadgets, short text in single lines to save space. Problem is, i dunno how to find out the number of lines i need for a given text.
thanx,
Searhin
is there a way to determine the length (in pixels- not characters) of a text to be displayed in a StringGadget or TextGadget?
I want to display text of varying lengths in deactivated StringGadgets. Long Texts should be displayed in MultiLine Gadgets, short text in single lines to save space. Problem is, i dunno how to find out the number of lines i need for a given text.
thanx,
Searhin
Code: Select all
Procedure TextWidth(text$)
GetTextExtentPoint32_(GetDC_(0), text$, Len(text$), sz.SIZE)
ProcedureReturn sz\cx
EndProcedure
El_Choni
Have in mind that it gives width for text with the default GUI font. If you change font, you should use this (after UseFont() or SetGadgetFont()):
Code: Select all
Procedure TextWidth(text$, WindowID)
hDC = GetDC_(WindowID)
GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE)
ReleaseDC_(WindowID, hDC)
ProcedureReturn sz\cx
EndProcedure
El_Choni
None API based one:
Code: Select all
If StartDrawing(WindowOutput())
Length = TextLength("Hahah")
StopDrawing()
EndIf
> A TextHeight(text$) - function would be nice.
Try this:
viewtopic.php?t=3801
Not sure if it does what you want, but the value of "tm\tmHeight" that it
returns might be the height of the text. Give it a try...
Try this:
viewtopic.php?t=3801
Not sure if it does what you want, but the value of "tm\tmHeight" that it
returns might be the height of the text. Give it a try...
This works with height, too:
Now, don't tell me there was also a TextHeight() command in PB
Code: Select all
Procedure TextHeight(text$, WindowID)
hDC = GetDC_(WindowID)
GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE)
ReleaseDC_(WindowID, hDC)
ProcedureReturn sz\cy
EndProcedure
El_Choni
That doesn't do what he asked for because the default font inside StartDrawing() and StopDrawing() is different from the default GUI font.Fred wrote:None API based one:Code: Select all
If StartDrawing(WindowOutput()) Length = TextLength("Hahah") StopDrawing() EndIf