An edittext control is used to place an editable text field where the user can type and edit text.
The syntax is:
edittext <name> [<caption>] [text:<string>] [fieldWidth:<integer>] [height:<integer>] [bold:<boolean>] [labelOnTop:<boolean>] [readOnly:<boolean>] [toolTip:<string>] [multiLine:<boolean>]
The default alignment of edittext
items is #left
.
Parameters:
text:
The text string in the edit box. To specify a multiline text as parameter, both carriage return \r and new line \n sequences should be specified, for example "First Line \r\nSecond Line".
fieldWidth:
The width in pixels of the edit box. By default, the width is set to be from just after the caption text to the right margin of the rollout.
height:
If an explicit height:
parameter is supplied on an edittext item definition that specifies a pixel height greater than one line of text (17 pixels), that edittext item becomes a multi-line edit box, allowing multiple lines of text to be entered.
multiLine
to false. See below. If you specify the height of the edittext to be 17 pixels or more, OR .multiLine
was specified as true regardless of the .height
, the on entered
event handler will not be called since the edittext will be in multi-line mode!
bold:
If set to true
, the text string in the edit box is displayed in bold format, if set to false
, in normal, non-bold format. The default value is false
.
labelOnTop:
If set to true
, the caption is placed above the edit text box. If false
or not specified, the caption is placed to the left of the edit text box.
readOnly:
When set to true
, the user cannot copy and paste or enter text in the edittext control. When false
or not specified, the user can enter, copy and paste text in the edittext control.
toolTip:
Provides text for a tooltip for the EditText; no tooltip if unsupplied. Available in in 3ds Max 2017 and higher.
multiLine:
Specifies whether the edittext control is a multi-line control. This argument overrides the behavior where any height larger than 17 automatically causes the control to become a multi-line control. So, for example, an edittext displaying a single line can be made multiline, and conversely an edittext with a height of 34 can be forced to be a single-line control. Available in 3ds Max 2020.1 Update and higher.
Properties:
<edittext>.text String
The text in the edit box. To specify a multiline text as parameter, both carriage return \r and new line \n sequences should be specified, for example "First Line \r\nSecond Line".
<edittext>.caption String
The text of the optional caption next to the edit box.
<edittext>.bold Boolean
If true
, the text is displayed in bold format, if false
, in normal, non-bold format.
<edittext>.width Integer
Get/set the width of the edittext window in pixels.
<edittext>.height Integer
Get/set the height of the edittext window in pixels.
<edittext>.readOnly
When set to true
, the user cannot copy and paste or enter text in the edittext control. When false
or not specified, the user can enter, copy and paste text in the edittext control.
Events:
on <edittext> changed <arg> do <expr>
Called each time the user changes the text in the edit box; the <arg>
argument will contain the new text in the edit box.
on <edittext> entered <arg> do <expr>
Called when the user enters text in the edit box and then presses ENTER or TAB to move the cursor out of the field. The <arg>
argument will contain the new text in the edit box.
ONCE AGAIN, IN CASE YOU MISSED THE PREVIOUS Warning, if you specify the .height
of the edittext to be 17 pixels or more, OR .multiLine
was specified as true regardless of the .height
, the on entered
event handler will not be called since the edittext will be in multi-line mode!
In single-line mode (default height, or less than 17 pixels), if you enter a string in the edit box and then press ENTER, the on changed
handler is called once per character and once for the ENTER. The on entered
handler is just called once, for the ENTER.
When in multi-line mode, ENTER keystrokes no longer cause the 'on entered'
handler to be called, but are inserted into the edit box as new lines.
They do, of course, cause 'on changed'
handlers to be called. These are called on every keystroke.
For multi-line edittext items, 'on entered'
handlers are called when the edit box loses keyboard focus, such as if you tab or click out of the edit box.
EXAMPLE:
rollout boxCreator "Box Creator" ( --define an edittextwith width 100 and the label on top: edittext prefix_txt "Name prefix:" fieldWidth:200 labelOnTop:true --If the user entered a new name... on prefix_txt entered txt do ( --And the name is not the empty string, if txt != "" do ( --Create a new box at a random position --somewhere between the given coordinates: new_obj = box pos:(random [-100,-100,-100] [100,100,100]) --Set the name of the new object to the prefix entered, --but add unique suffix to avoid duplicate names: new_obj.name = (uniquename txt) --And finally clear the edittext for a new entry --by assigning an empty string to the text property: prefix_txt.text = "" ) ) ) createDialog boxCreator 300 60 --create a Dialog from the rollout
Since 3ds Max 2015, pressing the ESC key will switch focus away from the edittext control to its parent window.