Skip to content

XTextField

Below is the CrossBasic API reference for the XTextField class.


Class: XTextField

A single-line text‑entry RichEdit control, supporting dark mode, custom colors, bevel/border, and a TextChanged event .

' Create a new text field.
Dim tf As New XTextField

Constructor / Destructor

Function Signature Description
Close Close() Destroys the instance.

Properties

All setters immediately update the native control if it’s already created.

Name Type Get / Set Description
Left Integer Left_GET(h) / Left_SET(h, v) X‑position within parent.
Top Integer Top_GET(h) / Top_SET(h, v) Y‑position within parent.
Width Integer Width_GET(h) / Width_SET(h, v) Control width.
Height Integer Height_GET(h) / Height_SET(h, v) Control height.
Parent Integer Parent_GET(h) / Parent_SET(h, ph) Host window handle (XWindow handle).
Text String Text_GET(h) / Text_SET(h, s) Current text.
TextColor Color TextColor_GET(h) / TextColor_SET(h, 0xRRGGBB) Text RGB color.
BackgroundColor String BackgroundColor_GET(h) / BackgroundColor_SET(h, "&hRRGGBB") Background RGB as Xojo‑style hex.
BorderColor String BorderColor_GET(h) / BorderColor_SET(h, "&hRRGGBB") Border RGB as hex.
HasBorder Boolean HasBorder_GET(h) / HasBorder_SET(h, b) Draws a single‑pixel border.
HasBevel Boolean HasBevel_GET(h) / HasBevel_SET(h, b) Toggles WS_BORDER style for 3D look.
FontName String FontName_GET(h) / FontName_SET(h, name) Face name (e.g. "Segoe UI").
FontSize Integer FontSize_GET(h) / FontSize_SET(h, size) Point size.
Enabled Boolean Enabled_GET(h) / Enabled_SET(h, b) Gray‑outs when False.
Visible Boolean Visible_GET(h) / Visible_SET(h, b) Show/hide control.
TextChanged String TextChanged_GET(h) Returns event token string, e.g. "xtextfield:12345678:TextChanged".
' Position and style:
tf.Left = 10
tf.Top = 20
tf.Width = 200
tf.Height = 24
tf.TextColor = &h0000FF  ' blue text
tf.BackgroundColor = "&hFFFFFF"  ' white bg
tf.HasBorder = True

Methods

Name Signature Description
Invalidate Invalidate() Forces redraw (useful after color changes).
' Redraw background/text after dynamic change:
Invalidate()

' Hook the TextChanged event:
Dim token As New XTextField
AddHandler(token.TextChanged, AddressOf(OnTextChanged))

Events

  • TextChanged Fired whenever the user types or pastes text.

  • Handler signature: Sub TextChanged(param As String)

  • param is the new full text.
Sub OnTextChanged(newText As String)
  Print "User typed: " + newText
End Sub

Complete Example

Sub Main()
  ' Create and parent to the main window (handle 0 assumed):
  Dim tfH As new XTextField
  tfH.Parent = win.Handle
  tfH.Left = 50
  tfH.Top = 50
  tfH.Width = 300
  tfH.Height = 30

  'Style
  tfH.BackgroundColor = "&h202020"  ' dark gray bg
  tfH.HasBorder = True
  tfH.FontName = "Consolas"
  tfH.FontSize = 12
  tfH. TextColor = &h00AA00          ' green text

  AddHandler(tfH.TextChanged, AddressOf(TextChangedHandler))

  ' … your app’s message loop …
  While True
    DoEvents()
    Sleep(1)
  Wend

End Sub

Sub TextChangedHandler(txt As String)
  Print "New content: " + txt
End Sub