I have found a very simple solution to my problem - just posting it so if
anyone else wants to try this, they can.
It's based off of what Clive Lumb said.
I temporarily put 3 textboxes on the screen. On resize i just put the form
width and height and fontsize there so i can watch the size setting.
Basically I found ( with my window layout ) font size 232 was teh biggest
font size i wanted.
Then I took the font size on an inbetween window size - and divided it by
the form height and got a 66% font size to height ratio
then I took the font size and divided it by the width and got a 22% font
size to width ratio.
In the end...I take the height and multiply it by 66%
take the height and multiply it by the 21%
take the minimum of the two
works like a charm.
Thanks Clive - you got me on the right track.
the textbox's will be removed but I left them there so you get the idea.
===
TextBox1.Text = Me.Size.Width.ToString
TextBox2.Text = Me.Size.Height.ToString
Dim CalcFontSizeA As Integer = Math.Min(232,
CType(Math.Round(Me.Label2.Height * 0.66, 0), Integer))
Dim CalcFontSizeB As Integer = Math.Min(232,
CType(Math.Round(Me.Label2.Width * 0.21, 0), Integer))
Dim FinalFontSize As Integer = Math.Min(CalcFontSizeA,
CalcFontSizeB)
Label2.Font = New Font(Label2.Font.Name, FinalFontSize,
Label2.Font.Style) )
TextBox3.Text = Label2.Font.Size.ToString
===
Thank you,
Cheers'
Miro
"Miro" <mi**@beero.comwrote in message
news:ud**************@TK2MSFTNGP02.phx.gbl...
Yeah I have started looking at finding the ratio,
Another thought I had is to do some benchmarks in some if statements -
that might be easier if i cannot find the ratio easily.
Thanks for your help...
Ill be playing with this this weekend.
Miro
"Clive Lumb" <clumb2@gratuit_en_anglais.fr.invalidwrote in message
news:uL**************@TK2MSFTNGP02.phx.gbl...
>"Miro" <mi**@beero.coma écrit dans le message de news:
ei**************@TK2MSFTNGP04.phx.gbl...
>>Is there a way to / or a mathematical formula to see if a font size is
'too big' for a label.
I have a label that is docked to 'fill' a form, and I want to resize
that font based on the width and height of the label.
So far I have something like this on the Form_Resize event:
Label2.Font = New Font(Label2.Font.Name, _
Label2.Size.Height - 100, Label2.Font.Style)
but it only works to a point, once the height gets past a certain point,
the font is simply too big for the label.
I know I can add some math for a maximum font size compared to the
height and width of the label, but im wondering if there is another
simpler way of a mathematical formula to do this in one shot.
Thanks,
You want to be looking at the font's height to size ratio (which is
fixed, but varies from font to font)
In pseudocode you need to do this
Ratio = font.height/font.size
New font size= label.height/Ratio
If you need to adjust the width to the content (or the content to the
width) use TextRenderer.MeasureText with the font from the label.
Good luck