|
-
Apr 14th, 2000, 12:18 AM
#1
Thread Starter
Junior Member
How can I get text's width and height in pixels (I can't use TextWidth and TextHeight)?
There's one API function for this, but I don't know how to use it! That function was, if I remember correctly, GetTextMetrics.
-
Apr 14th, 2000, 12:39 AM
#2
Getting the texts width and heigth using GetTextMetrics is almost undoable. Consider different widths for every character, and don't forget there can be a overlapping of characters (eg some fonts have the upper part of the f invading the space of the next character).
What is wrong with TextWidth and TextHeight? If the scalemode isn't set to pixels, you could do a conversion.
To give you an idea of the complexity of GetTextMetrics, It uses a TEXTMETRIC structure which is defined as follows.
Code:
Type TEXTMETRIC ' 53 Bytes
tmHeight As Long
tmAscent As Long
tmDescent As Long
tmInternalLeading As Long
tmExternalLeading As Long
tmAveCharWidth As Long
tmMaxCharWidth As Long
tmWeight As Long
tmOverhang As Long
tmDigitizedAspectX As Long
tmDigitizedAspectY As Long
tmFirstChar As Byte
tmLastChar As Byte
tmDefaultChar As Byte
tmBreakChar As Byte
tmItalic As Byte
tmUnderlined As Byte
tmStruckOut As Byte
tmPitchAndFamily As Byte
tmCharSet As Byte
End Type
-
Apr 14th, 2000, 01:58 AM
#3
Hyperactive Member
Well, why not post the rest of the code it sounds like something I could use too.
-
Apr 14th, 2000, 04:32 PM
#4
I haven't got any code. It just looked it up because you mentioned it. The API declaration is :
Public Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long
Call it with the device context of the object that has the font selected, pass a variable of type TEXTMETRIC and it will fill the structure for you. To get the actual textwidth is a different thing. Maybe you can use the tmAveCharWidth, but this will only give you an average.
-
Apr 14th, 2000, 05:45 PM
#5
Fanatic Member
So how do you do it then???
I'd like to be able to resize a label or textbox to exactly fit the text no matter the font etc.
...and say resize it on the text_change event
-
Apr 14th, 2000, 09:25 PM
#6
As far as the label is concerned, why not use the .AutoSize property of it? This will adjust the size of the label to the text that it contains.
Imar
-
Apr 14th, 2000, 10:12 PM
#7
Fanatic Member
grrrr.
I'm not really looking for a quick work around (I know this isn't my thread but I understand his point).
lets say I want to resize all the columns of a Flexgrid by the width of the widest row entry in that column (like excel/explorer does) on double click of column header seperator.
??????????????????????????????????????????
-
Apr 15th, 2000, 02:35 PM
#8
Thread Starter
Junior Member
I need this width and height for DirectX.
>??????????????????????????????????????????
I agree
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|