Difference between revisions of "Documentation/DevGuide/Basic/Text Field"
m (adding short basic code) |
|||
Line 10: | Line 10: | ||
The text field control <idl>com.sun.star.awt.UnoControlEdit</idl> is used to get input from the user at runtime. In general, the text field is used for editable text, but it can also be made read-only by setting the <code>ReadOnly</code> property to <code>True</code>. The actual text displayed in a text field is controlled by the <code>Text</code> property. The maximum number of characters that can be entered by the user is specified with the <code>MaxTextLen</code> property. A value of 0 means that there is no limitation. By default, a text field displays a single line of text. This behavior is changed by setting the property <code>MultiLine</code> to <code>True</code>. The properties <code>HScroll</code> and <code>VScroll</code> displays a horizontal and vertical scroll bar. | The text field control <idl>com.sun.star.awt.UnoControlEdit</idl> is used to get input from the user at runtime. In general, the text field is used for editable text, but it can also be made read-only by setting the <code>ReadOnly</code> property to <code>True</code>. The actual text displayed in a text field is controlled by the <code>Text</code> property. The maximum number of characters that can be entered by the user is specified with the <code>MaxTextLen</code> property. A value of 0 means that there is no limitation. By default, a text field displays a single line of text. This behavior is changed by setting the property <code>MultiLine</code> to <code>True</code>. The properties <code>HScroll</code> and <code>VScroll</code> displays a horizontal and vertical scroll bar. | ||
− | When a text field receives the focus by pressing the '''TAB''' key the displayed text is selected and highlighted by default. The default cursor position within the text field is to the right of the existing text. If the user starts typing while a block of text is selected, the selected text is replaced. In some cases, the user may change the default selection behavior and set the selection manually. This is done using the <idl>com.sun.star.awt.XTextComponent</idl> interface: | + | When a text field receives the focus by pressing the {{key|'''TAB'''}} key the displayed text is selected and highlighted by default. The default cursor position within the text field is to the right of the existing text. If the user starts typing while a block of text is selected, the selected text is replaced. In some cases, the user may change the default selection behavior and set the selection manually. This is done using the <idl>com.sun.star.awt.XTextComponent</idl> interface: |
− | < | + | <syntaxhighlight lang="oobas"> |
Dim sText As String | Dim sText As String | ||
Dim oSelection As New com.sun.star.awt.Selection | Dim oSelection As New com.sun.star.awt.Selection | ||
Line 26: | Line 26: | ||
oSelection.Max = Len( sText ) | oSelection.Max = Len( sText ) | ||
oTextField.setSelection( oSelection ) | oTextField.setSelection( oSelection ) | ||
− | </ | + | </syntaxhighlight> |
Or in short: | Or in short: | ||
− | < | + | <syntaxhighlight lang="oobas"> |
Dim oSelection As New com.sun.star.awt.Selection | Dim oSelection As New com.sun.star.awt.Selection | ||
Line 38: | Line 38: | ||
oSelection.Max = Len( sText ) | oSelection.Max = Len( sText ) | ||
oTextField.Selection = oSelection | oTextField.Selection = oSelection | ||
− | </ | + | </syntaxhighlight> |
The text field control is also used for entering passwords. The property <code>EchoChar</code> specifies the character that is displayed in the text field while the user enters the password. In this context, the <code>MaxTextLen</code> property is used to limit the number of characters that are typed in: | The text field control is also used for entering passwords. The property <code>EchoChar</code> specifies the character that is displayed in the text field while the user enters the password. In this context, the <code>MaxTextLen</code> property is used to limit the number of characters that are typed in: | ||
− | < | + | <syntaxhighlight lang="oobas"> |
oTextFieldModel = oDialog.Model.TextField1 | oTextFieldModel = oDialog.Model.TextField1 | ||
oTextFieldModel.EchoChar = Asc("*") | oTextFieldModel.EchoChar = Asc("*") | ||
oTextFieldModel.MaxTextLen = 8 | oTextFieldModel.MaxTextLen = 8 | ||
− | </ | + | </syntaxhighlight> |
A user can enter any kind of data into a text field, such as numerical values and dates. These values are always stored as a string in the Text property, thus leading to problems when evaluating the user input. Therefore, consider using a date field, time field, numeric field, currency field or formatted field instead. | A user can enter any kind of data into a text field, such as numerical values and dates. These values are always stored as a string in the Text property, thus leading to problems when evaluating the user input. Therefore, consider using a date field, time field, numeric field, currency field or formatted field instead. | ||
Latest revision as of 12:39, 21 December 2020
The text field control com.sun.star.awt.UnoControlEdit is used to get input from the user at runtime. In general, the text field is used for editable text, but it can also be made read-only by setting the ReadOnly
property to True
. The actual text displayed in a text field is controlled by the Text
property. The maximum number of characters that can be entered by the user is specified with the MaxTextLen
property. A value of 0 means that there is no limitation. By default, a text field displays a single line of text. This behavior is changed by setting the property MultiLine
to True
. The properties HScroll
and VScroll
displays a horizontal and vertical scroll bar.
When a text field receives the focus by pressing the TAB key the displayed text is selected and highlighted by default. The default cursor position within the text field is to the right of the existing text. If the user starts typing while a block of text is selected, the selected text is replaced. In some cases, the user may change the default selection behavior and set the selection manually. This is done using the com.sun.star.awt.XTextComponent interface:
Dim sText As String Dim oSelection As New com.sun.star.awt.Selection REM get control oTextField = oDialog.getControl("TextField1") REM set displayed text sText = "Displayed Text" oTextField.setText( sText ) REM set selection oSelection.Min = 0 oSelection.Max = Len( sText ) oTextField.setSelection( oSelection )
Or in short:
Dim oSelection As New com.sun.star.awt.Selection oTextField = oDialog.getControl("TextField1") oTextField.Text = "Displayed Text" oSelection.Min = 0 oSelection.Max = Len( sText ) oTextField.Selection = oSelection
The text field control is also used for entering passwords. The property EchoChar
specifies the character that is displayed in the text field while the user enters the password. In this context, the MaxTextLen
property is used to limit the number of characters that are typed in:
oTextFieldModel = oDialog.Model.TextField1 oTextFieldModel.EchoChar = Asc("*") oTextFieldModel.MaxTextLen = 8
A user can enter any kind of data into a text field, such as numerical values and dates. These values are always stored as a string in the Text property, thus leading to problems when evaluating the user input. Therefore, consider using a date field, time field, numeric field, currency field or formatted field instead.
Content on this page is licensed under the Public Documentation License (PDL). |