Sub AdjustLabel(Lbl As Label, OriginalWidth As Int, OriginalHeight As Int)
Dim cnv As Canvas
Dim bmp As Bitmap
bmp.InitializeMutable(2dip, 2dip)
cnv.Initialize2(bmp)
Dim MeasuredStringWidth As Int 'ignore
MeasuredStringWidth = cnv.MeasureStringWidth(Lbl.Text, Lbl.Typeface, Lbl.TextSize)
Lbl.Width = OriginalWidth
Lbl.Height = OriginalHeight
If MeasuredStringWidth < OriginalWidth - Lbl.Padding(0) - Lbl.Padding(2) Then
Lbl.Width = MeasuredStringWidth + Lbl.Padding(0) + Lbl.Padding(2)
Else
Dim lblDummy As Label
lblDummy.Initialize("")
Dim Parent As Panel = Lbl.Parent
Parent.AddView(lblDummy, 0, 0, Lbl.Width - Lbl.Padding(0) - Lbl.Padding(2), Lbl.Height - Lbl.Padding(1) - Lbl.Padding(3))
lblDummy.Text = Lbl.Text
lblDummy.TextSize = Lbl.TextSize
lblDummy.Typeface = Lbl.Typeface
Dim su As StringUtils
Lbl.Height = su.MeasureMultilineTextHeight(lblDummy, Lbl.Text) + Lbl.Padding(1) + Lbl.Padding(3)
lblDummy.RemoveView
End If
End Sub