From Xojo Documentation
Jump to: navigation, search
For web applications, see WebTextField.

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

AcceptTabs ReadOnlyProperty.png LimitText SelStart
Active ReadOnlyProperty.png LiveUpdate SelText
Alignment LockBottom SelTextColor
AutoDeactivate LockLeft SelTextFont
AutomaticallyCheckSpelling LockRight SelTextSize
BackColor LockTop TabIndex
Bold Mask TabStop
Border ReadOnlyProperty.png MouseCursor Text
CueText MouseX ReadOnlyProperty.png TextColor
DataField MouseY ReadOnlyProperty.png TextFont
DataSource Name TextSize
Enabled PanelIndex TextUnit
Format Parent Top
Handle ReadOnlyProperty.png Password TrueWindow ReadOnlyProperty.png
Height ReadOnly Underline
HelpTag Scope ReadOnlyProperty.png UseFocusRing
Index ReadOnlyProperty.png SelAlignment Visible
Italic SelLength Width
Left SelPlain Window ReadOnlyProperty.png

AcceptFileDrop Close Refresh
AcceptPictureDrop Copy RefreshRect
AcceptRawDataDrop DrawInto ScrollPositionX
AcceptTextDrop InsertionPosAtXY SelectAll
AppendText Invalidate SetFocus
CharPosAtLineNum LineNumAtCharPos SetString
CharPosAtXY Paste


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 appending 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 Text 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 AppendText method instead. Simply pass it the text to be appended. 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.

Dim f As FolderItem
Dim i As Integer
Dim stream As BinaryStream
f = GetOpenFolderItem(FileTypes1.Text) // file type defined in File type set
If f <> Nil Then
stream = BinaryStream.Open(f, False)
TextField1.AppendText(stream.Read(1000, Encodings.UTF8))
Loop Until stream.EOF
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 Text or SelText properties, this text is returned in UTF-8.

Using Class Constants

Set the alignment of the entire contents of the TextField by assigning a constant to the Alignment property. The following class constants are available:

Value Class Constant Description
0 AlignDefault The default alignment. Currently, the same as AlignLeft.
1 AlignLeft Left alignment.
2 AlignCenter Center alignment.
3 AlignRight Right alignment.

For example, the following code in the Action event of a control array sets the alignment of the text in a TextField. The Action event is passed an index parameter that indicates which control was clicked.

Sub Action (Index As Integer)
Select Case Index
Case 0
TextField1.Alignment = TextField.AlignDefault
Case 1
TextField1.Alignment = TextField.AlignLeft
Case 2
TextField1.Alignment = TextField.AlignCenter
Case 3
TexField1.Alignment = TextField.AlignRight
End Select

See Also

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

Personal tools

Starting Out
Dig Deeper
More Help