[B4X] Custom Views with Enhanced Designer Support
Custom views are implemented as B4X classes or in a library. A custom view includes a set of properties that can be set from the visual designer. Note that the visual designer will show a box instead of the actual view. Using custom views is very simple. You need to add the class or library to...
www.b4x.com
I run the example project above. I can see that the font size is different in the view added by designer vs view created by code programmatically. (LabeledTextField2 is smaller)
How is the font size property value determined if no value is specified in the code?
B4X:
' Example creating by code
LabeledTextField2.Initialize(Me, "LabeledTextField2")
LabeledTextField2.AddToParent(MainForm.RootPane, 20, 200, 200,30)
LabeledTextField2.LabelText = "Enter 2:"
LabeledTextField2.FieldValue = "Hello World 2"
When I try to add another custom view by code, the width and height are not changed accordingly (no effect).
B4X:
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private btnShowFieldContent As Button
Private LabeledTextField1 As LabeledTextField
Private LabeledTextField2 As LabeledTextField
Private LabeledTextField3 As LabeledTextField
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.SetFormStyle("UTILITY")
MainForm.RootPane.LoadLayout("Main")
MainForm.Title = "B4J HowTo Custom View Example - LabeledTextField"
MainForm.Show
CallSubDelayed(Me, "Resize")
'
' Example creating by code
LabeledTextField2.Initialize(Me, "LabeledTextField2")
LabeledTextField2.AddToParent(MainForm.RootPane, 20, 200, 200, 30)
LabeledTextField2.LabelText = "Enter 2:"
LabeledTextField2.FieldValue = "Hello World 2"
LabeledTextField3.Initialize(Me, "LabeledTextField3")
LabeledTextField3.AddToParent(MainForm.RootPane, 20, 250, 300, 60)
LabeledTextField3.LabelText = "Enter 3:"
LabeledTextField3.FieldValue = "Hello World 3"
LabeledTextField3.SetWidth(300)
LabeledTextField3.SetHeight(60)
End Sub
Sub Resize
CallSubDelayed2(LabeledTextField1, "SetWidth", 100)
LabeledTextField1.Top = 20
LabeledTextField1.Left = 20
End Sub
Sub btnShowFieldContent_Action
fx.Msgbox(Null, $"The content of the LabeledTextField:${CRLF}1=${LabeledTextField1.GetFieldValue}${CRLF}2=${LabeledTextField2.GetFieldValue}"$, "Info")
End Sub