Public Sub Ideal_Text_Size(Text_to_Size As String, TestLabel As Label, InitialSize As Int, SorM As String) As Int
Private TextSizeBasedOnHeight As Int
Private TextSizeBasedOnWidth As Int
Private FontSizeWidth As Int = InitialSize
Private FontSizeHeight As Int = InitialSize
Private CorrectSize As Int
' Private CVS As Canvas
' CVS.Initialize(TestLabel)
Private Padding(4) As Int
Padding = TestLabel.Padding
' TextSizeBasedOnWidth = CVS.MeasureStringWidth(Text_to_Size, TestLabel.Typeface, FontSizeWidth)
'
' Do Until TextSizeBasedOnWidth < TestLabel.Width-Padding(0)-Padding(2)
' TextSizeBasedOnWidth = CVS.MeasureStringWidth(Text_to_Size, TestLabel.Typeface, FontSizeWidth)
' FontSizeWidth = FontSizeWidth-1
' Loop
TestLabel.TextSize = FontSizeHeight
TextSizeBasedOnHeight = su.MeasureMultilineTextHeight(TestLabel, Text_to_Size)
Do Until TextSizeBasedOnHeight < TestLabel.Height-Padding(1)-Padding(3)
FontSizeHeight = FontSizeHeight-1
TestLabel.TextSize = FontSizeHeight
TextSizeBasedOnHeight = su.MeasureMultilineTextHeight(TestLabel, Text_to_Size)
Loop
' If SorM = "S" Then
' If FontSizeWidth <= FontSizeHeight Then
' CorrectSize = FontSizeWidth
' Else
' CorrectSize = FontSizeHeight
' End If
' Else If SorM = "M" Then
If FontSizeWidth >= FontSizeHeight Then
CorrectSize = FontSizeWidth
Else
CorrectSize = FontSizeHeight
End If
' End If
Return CorrectSize
End Sub