Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private fx As JFX
Dim cvs1 As B4XCanvas
Dim Fnt As B4XFont
Private DigitalFontTTF As String = "arial.ttf"
Private Pane1 As Pane
Private TextField1 As TextField
Private TextField2 As TextField
Private Label1 As Label
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Fnt = xui.CreateFont(fx.LoadFont("c:\phisicalFontPath", DigitalFontTTF, 35), 35)
' in designer label1 size must be also 35
End Sub
Private Sub Button1_Click
Dim text As String
cvs1.Initialize ( Pane1)
text="This is an example text to verify the label change width according to text lenght"
Dim r As B4XRect = cvs1.MeasureText(text, Fnt )
'''' cvs1.DrawText(text,10, 17 , Fnt, xui.Color_Blue , "LEFT") no need to draw, just for reference
''17 may be different according font size
Label1.PrefWidth=r.Width+17
Label1.Text=text
End Sub