PureBasic Forum https://www.purebasic.fr/english/ |
|
PxLenght of Text in String/TextGadget https://www.purebasic.fr/english/viewtopic.php?f=13&t=6251 |
Page 1 of 2 |
Author: | Searhin [ Mon May 26, 2003 11:13 am ] |
Post subject: | 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 |
Author: | El_Choni [ Mon May 26, 2003 12:08 pm ] |
Post subject: | |
Code: Procedure TextWidth(text$)
GetTextExtentPoint32_(GetDC_(0), text$, Len(text$), sz.SIZE) ProcedureReturn sz\cx EndProcedure |
Author: | Searhin [ Mon May 26, 2003 2:18 pm ] |
Post subject: | |
WOW! thanx - that's even easier than i thought ![]() |
Author: | El_Choni [ Mon May 26, 2003 3:35 pm ] |
Post subject: | |
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: Procedure TextWidth(text$, WindowID)
hDC = GetDC_(WindowID) GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE) ReleaseDC_(WindowID, hDC) ProcedureReturn sz\cx EndProcedure |
Author: | Searhin [ Mon May 26, 2003 4:55 pm ] |
Post subject: | |
ah, okay - now it gives the correct results thanx again |
Author: | Fred [ Mon May 26, 2003 8:41 pm ] |
Post subject: | |
None API based one: Code: If StartDrawing(WindowOutput())
Length = TextLength("Hahah") StopDrawing() EndIf |
Author: | El_Choni [ Mon May 26, 2003 11:54 pm ] |
Post subject: | |
![]() I had asked for this function several times, and it was already there. Sorry. |
Author: | Searhin [ Tue May 27, 2003 11:05 am ] |
Post subject: | |
being most embarassed... ![]() |
Author: | Fred [ Tue May 27, 2003 3:03 pm ] |
Post subject: | |
No problem guys ![]() |
Author: | GPI [ Tue May 27, 2003 5:06 pm ] |
Post subject: | |
A TextHeight(text$) - function would be nice. |
Author: | PB [ Wed May 28, 2003 5:20 am ] |
Post subject: | |
> A TextHeight(text$) - function would be nice. Try this: http://forums.purebasic.com/english/vie ... 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... |
Author: | El_Choni [ Wed May 28, 2003 12:45 pm ] |
Post subject: | |
This works with height, too: Code: Procedure TextHeight(text$, WindowID) hDC = GetDC_(WindowID) GetTextExtentPoint32_(hDC, text$, Len(text$), sz.SIZE) ReleaseDC_(WindowID, hDC) ProcedureReturn sz\cy EndProcedure Now, don't tell me there was also a TextHeight() command in PB ![]() |
Author: | Fred [ Wed May 28, 2003 1:12 pm ] |
Post subject: | |
I guess it will be soon then ![]() |
Author: | Gansta93 [ Thu Oct 21, 2004 12:57 pm ] |
Post subject: | |
It would be better if we wouldn't have to do StartDrawing() and StopDrawing() to know the width in pixels of a text. It would be faster. Time is monay ![]() |
Author: | Trond [ Tue Jul 18, 2006 9:44 pm ] |
Post subject: | |
Fred wrote: None API based one: That doesn't do what he asked for because the default font inside StartDrawing() and StopDrawing() is different from the default GUI font.
Code: If StartDrawing(WindowOutput()) Length = TextLength("Hahah") StopDrawing() EndIf |
Page 1 of 2 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |