DesktopTextField

From Xojo Documentation

Class (inherits from DesktopTextControl)


New in 2021r3

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

Events
Closing FocusReceived MouseUp
ConstructContextualMenu KeyDown MouseWheel
ContextualMenuItemSelected KeyUp Opening
DragEnter MenuBarSelected SelectionChanged
DragExit MouseDown TextChanged
DragOver MouseEnter ValidationFailed
DropObject MouseExit
FocusLost MouseMove


Properties
Active fa-lock-32.png Hint SelectedText
AllowAutoDeactivate HorizontalScrollPosition SelectionLength
AllowFocusRing Index fa-lock-32.png SelectionPlain
AllowSpellChecking Italic SelectionStart
AllowTabStop Left TabIndex
AllowTabs LockBottom Text
BackgroundColor LockLeft TextAlignment
Bold LockRight TextColor
Enabled LockTop Tooltip
FontName MaximumCharactersAllowed Top
FontSize MouseCursor Transparent
FontUnit Name fa-lock-32.png Underline
Format PanelIndex ValidationMask
FormattedText fa-lock-32.png Parent Visible
Handle fa-lock-32.png Password Width
HasBorder ReadOnly Window fa-lock-32.png
Height Scope fa-lock-32.png
Methods
AcceptFileDrop CharacterPosition LineNumber
AcceptPictureDrop Close Paste
AcceptRawDataDrop Copy Refresh
AcceptTextDrop DrawInto SelectAll
AddText InsertionPosition SetFocus

Notes

Execution order of MenuHandlers

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

Adding Text to a TextField

When adding text to a DesktopTextField, you may notice some flicker as the DesktopTextField redraws to show the new text. This will happen if you appended the Value property of the DesktopTextField 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. Simply 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)
Do
TextField1.AddText(stream.Read(1000, Encodings.UTF8))
Loop Until stream.EndOfFile
stream.Close
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 DesktopTextField via the TextAlignment property.

See Also

Font, FontCount functions; Paragraph, Range, StyleRun, StyledText, StyledTextPrinter, DesktopTextArea, DesktopTextControl classes.