From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from TextEdit)

The standard editable text field used by desktop applications. A TextField control can contain one line of text, with one font, font size, and style. Use TextArea if you need multiple lines of text or styled text.

Close GotFocus MouseUp
ConstructContextualMenu KeyDown MouseWheel
ContextualMenuAction KeyUp Open
DragEnter LostFocus SelChange
DragExit MouseDown TextChange
DragOver MouseEnter ValidationError
DropObject MouseExit
EnableMenuItems MouseMove
Active fa-lock-32.png Index fa-lock-32.png SelectedText
AllowAutoDeactivate Italic SelectionLength
AllowFocusRing Left SelectionPlain
AllowSpellChecking LiveUpdate SelectionStart
AllowTabStop LockBottom TabIndex
AllowTabs LockLeft Text
BackgroundColor LockRight TextAlignment
Bold LockTop TextColor
Enabled MaximumCharactersAllowed Tooltip
FontName MouseCursor Top
FontSize MouseX fa-lock-32.png Transparent
FontUnit MouseY fa-lock-32.png TrueWindow fa-lock-32.png
Format Name fa-lock-32.png Underline
Handle fa-lock-32.png PanelIndex ValidationMask
HasBorder Parent Visible
Height Password Width
Hint ReadOnly Window fa-lock-32.png
HorizontalScrollPosition Scope fa-lock-32.png
AcceptFileDrop Close Paste
AcceptPictureDrop Copy Refresh
AcceptRawDataDrop DrawInto SelectAll
AcceptTextDrop InsertionPosition SetFocus
AddText Invalidate
CharacterPosition LineNumber


Execution order of MenuHandlers

The intrinsic control menu handlers (such as TextField.SelectAll) are handled after any user-defined menu handlers on the TextField subclass (if it was subclassed). This means that if you have a SelectAll handler on the Window of the TextField, it will no longer be called when the TextField has focus, because the TextField will now handle it first. In this situation, create a TextField subclass that defines its own SelectAll handler, and handle the desired behavior there.

Adding Text to a TextField

When adding text to a TextField, you may notice some flicker as the TextField redraws to show the new text. This will happen if you appended the Value property of the TextField like this:

TextField1.Text = TextField1.Text + "my new text"

This occurs because the entire contents of the TextField has to be redrawn. To avoid this flicker, call the AddText method instead. Pass it the text to be added. For example, this code reads an external text file into a TextField using the Read method of the Readable class interface. The text is read in groups of 1000 characters until the end-of-file is reached.

Var f As FolderItem
Var i As Integer
Var stream As BinaryStream
f = FolderItem.ShowOpenFileDialog(FileTypes1.Text) // file type defined in File type set
If f <> Nil Then
stream = BinaryStream.Open(f, False)
TextField1.AddText(stream.Read(1000, Encodings.UTF8))
Loop Until stream.EndOfFile
End If

Text Encoding

TextFields store all text internally in Unicode, which is able to represent a mixture of characters from different writing systems. When you extract the text via the Value or SelectedText properties, this text is returned in UTF-8.

Windows Info

Changing the TextColor property for a read-only TextField on Windows does not change the color. It is native Windows behavior for the field text to remain black.

Handling TextAlignment

Set the alignment of the entire contents of the TextField via the TextAlignment property.

See Also

Font, FontCount functions; Paragraph, Range, StyleRun, StyledText, StyledTextPrinter, TextArea, TextEdit classes.