For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > February 2005 > How to relate label's height to the font size?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to relate label's height to the font size?
Jack

2005-02-27, 3:55 am

I want to give user option to select the font size.
Experimentally I found the proper label's height values, but I do not think
it is a proper way.
Is there any formula covering that?


alpine

2005-02-27, 3:55 am

On Sat, 26 Feb 2005 23:50:49 -0500, "Jack" <replytonewsgroup@please>
wrote:

>I want to give user option to select the font size.
>Experimentally I found the proper label's height values, but I do not think
>it is a proper way.
>Is there any formula covering that?



Have you looked at the AutoSize property for the label?

HTH,
Bryan
________________________________________
____________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas
Larry Serflaten

2005-02-27, 3:55 am


"Jack" <replytonewsgroup@please> wrote
> I want to give user option to select the font size.
> Experimentally I found the proper label's height values, but I do not think
> it is a proper way.
> Is there any formula covering that?


Not one you'd want to use. You can get VB to tell you what size the
text will be. Add a Label and a Button to a new form and try out the
test code below....

LFS

Private Sub Command1_Click()
Dim siz As Long

Label1.AutoSize = True
siz = 8
Do While siz < 100
' Change size
Label1.Font.Size = siz
' Copy font to Form
Set Me.Font = Label1.Font
' Compare values
Debug.Print "SIZE: "; siz,
Debug.Print "TEXT: "; Me.TextHeight(Label1.Caption)
Debug.Print "LABEL: "; Label1.Height,
' Increment size
siz = siz * 1.25
Loop

End Sub




Jack

2005-02-27, 8:55 pm

I missed that Autosize Label property :(.
Thank you for showing it.
But how it will be if I replace the label with the text box?
How to resize the height of textbox in relation to the font size?
Jack

"Jack" <replytonewsgroup@please> wrote in message
news:uH57nfIHFHA.1500@TK2MSFTNGP09.phx.gbl...
>I want to give user option to select the font size.
> Experimentally I found the proper label's height values, but I do not
> think it is a proper way.
> Is there any formula covering that?
>



alpine

2005-02-27, 8:55 pm

That's a bit more tricky. The best way would probably be to use the
GetTextExtentPoint32 API and then use GetClientRect and GetWindowRect
to APIs to determine the current size and make any adjustments from
there.

HTH,
Bryan
________________________________________
____________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'tsendspam@mvps.org Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


On Sun, 27 Feb 2005 16:47:38 -0500, "Jack" <replytonewsgroup@please>
wrote:
[color=darkred]
>I missed that Autosize Label property :(.
>Thank you for showing it.
>But how it will be if I replace the label with the text box?
>How to resize the height of textbox in relation to the font size?
>Jack
>
>"Jack" <replytonewsgroup@please> wrote in message
>news:uH57nfIHFHA.1500@TK2MSFTNGP09.phx.gbl...
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com