Sub SetTextSize(lbl As Label, txt As String)
Dim dt As Float
Dim limit = 1 As Float
Dim h As Int
'This loop determines how many CRLFs there are in the text.
Dim charcnt As Double
Dim x2, placer, placerct, ts As Int
For x = 0 To txt.Length -1
placerct = 0
charcnt = txt.Length
For x2 = 0 To charcnt
placer = txt.IndexOf2(Chr(10),x2)
If placer = -1 Then
Exit
Else
placerct = placerct + 1
x2 = placer
End If
Next
Next
If placerct > 0 Then
ts = 19 - (placerct * 2)
Else
ts = 24
End If
'Now, do the resizing:
lbl.Text = txt
lbl.TextSize = ts
dt = lbl.TextSize
h = stu.MeasureMultilineTextHeight(lbl, txt)
Do While dt > limit OR h > lbl.Height
dt = dt / 2.25
h = stu.MeasureMultilineTextHeight(lbl, txt)
If h > lbl.Height Then
lbl.TextSize = lbl.TextSize - dt
Else
lbl.TextSize = lbl.TextSize + dt
End If
Loop
End Sub