Skip to main content

TextBox Class

NuGet: GHIElectronics.TinyCLR.UI
Assembly: GHIElectronics.TinyCLR.UI
Namespace: GHIElectronics.TinyCLR.UI.Controls

An editable single-line text field that opens the on-screen keyboard when activated.

public class TextBox : Control

Constructors

TextBox()

public TextBox()

Initializes a new instance of the TextBox class.

Properties

TextAlign

public TextAlignment TextAlign { get; set; }

The horizontal alignment of the displayed text.

PasswordChar

public char PasswordChar { get; set; }

When set, the character displayed in place of each typed character to mask input.

Text

public string Text { get; set; }

The current text of the field.

BorderColor

public Color BorderColor { get; set; }

The color of the border drawn around the field.

BorderThickness

public ushort BorderThickness { get; set; }

The thickness in pixels of the border drawn around the field.

PaddingX

public ushort PaddingX { get; set; }

The horizontal padding in pixels between the border and the text.

PaddingY

public ushort PaddingY { get; set; }

The vertical padding in pixels between the border and the text.

Methods

SetTextBinding(object source, string propertyName, bool twoWay)

public void SetTextBinding(object source, string propertyName, bool twoWay = true)

One-way or two-way bind Text to a CLR property on source using reflection. For change notifications implement INotifyBindablePropertyChanged on the source.

ClearTextBinding()

public void ClearTextBinding()

Removes any binding previously set with SetTextBinding.

OnTouchUp(TouchEventArgs e)

protected override void OnTouchUp(TouchEventArgs e)

Focuses the field on tap and, unless a physical keyboard has suppressed it, opens the on-screen keyboard.

OnButtonDown(ButtonEventArgs e)

protected override void OnButtonDown(ButtonEventArgs e)

Hardware buttons: Select opens the on-screen keyboard (unless suppressed); Left/Right/Home move the caret. Arrow keys from a physical keyboard map here.

OnCharacter(char c)

protected override void OnCharacter(char c)

Inserts or removes a character at the caret (physical-keyboard text entry). Backspace = '\b', delete = (char)127.

OnGotFocus(FocusChangedEventArgs e)

protected override void OnGotFocus(FocusChangedEventArgs e)

Starts the blinking caret and moves it to the end of the text when the field gains focus.

OnLostFocus(FocusChangedEventArgs e)

protected override void OnLostFocus(FocusChangedEventArgs e)

Stops the blinking caret when the field loses focus.

MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)

protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight)

Measures the size needed for the text plus padding and border.

ArrangeOverride(int arrangeWidth, int arrangeHeight)

protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight)

Records the arranged size of the field.

OnRender(DrawingContext dc)

public override void OnRender(DrawingContext dc)

Draws the field's border and text (masked when PasswordChar is set).

Events

TextChanged

public event TextChangedEventHandler TextChanged

Raised when the text changes.

BindingError

public event BindingErrorEventHandler BindingError

Raised when a binding pull (source → TextBox) or push (TextBox → source) fails. Default behavior is silent (the framework can't sensibly recover); subscribe here to log or surface the error during development.