Developer Resources

TextBox

Overview

The TextBox class represents a text box control.

Base Class

FormControl

Constructor

TextBox(text : String, x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)

Arguments

text
The initial text of the control.
x_pos
The x position of the control.
y_pos
The y position of the control.
width
The width of the control.
height
The height of the control.

Events

TextBox.enterPressed
Fired when enter is pressed in the control.
TextBox.maxLengthExceeded
Fired when the maximum length of the text control is exceeded.
TextBox.textChanged
Fired when the text is updated in the control.

Methods

TextBox.appendText
Appends text to the text of the textbox.
TextBox.clear
Clears the textbox of all text.
TextBox.getInsertionPoint
Gets the insertion point for the textbox.
TextBox.getLineCount
Gets the number of lines in a textbox.
TextBox.getLineLength
Gets the number of characters on a line.
TextBox.getLineText
Gets the text on a specified line number.
TextBox.getMaxLength
Gets the maximum number of characters a textbox can have.
TextBox.getPasswordMode
Returns the state of the password mode for the textbox.
TextBox.getSelectedText
Gets the selected text in the textbox.
TextBox.getText
Gets the text of the textbox.
TextBox.isMultiline
Gets the multiline mode for the textbox.
TextBox.select
Selects text in the textbox.
TextBox.selectAll
Selects all the text in the textbox.
TextBox.setInsertionPoint
Sets the insertion point for the textbox.
TextBox.setMaxLength
Sets the maximum number of characters a textbox can have
TextBox.setMultiline
Sets the multiline mode for the textbox.
TextBox.setPasswordMode
Sets the state of the password mode for the textbox.
TextBox.setText
Sets the text for the textbox.

Inherited Methods

FormControl.captureMouse
Captures the mouse on this form control.
FormControl.disablePaint
Disables the window from redrawing itself.
FormControl.enablePaint
Enables the window to redraw itself.
FormControl.getBackgroundColor
Gets the background color of the form control.
FormControl.getClientSize
Gets the client size of the form control.
FormControl.getEnabled
Indicates whether or not a form control is enabled.
FormControl.getFont
Gets the default font for the text of form control.
FormControl.getForegroundColor
Gets the foreground color of the form control.
FormControl.getMaxSize
Gets the maximum size of the form control.
FormControl.getMinSize
Gets the minimum size of the form control.
FormControl.getMousePosition
Gets the mouse position relative to this form control.
FormControl.getNativeHandle
Gets the native handle of the window/control
FormControl.getPosition
Gets the position of a form control.
FormControl.getSize
Gets the size of the form control.
FormControl.invalidate
Invalidates a form control, which will cause it to be repainted on the next paint event.
FormControl.refresh
Refreshes a form control, which immediately repaints the entire form control.
FormControl.releaseMouse
Releases the mouse from being captured on this form control.
FormControl.setBackgroundColor
Sets the background color of the form control.
FormControl.setClientSize
Sets the client size of a form control.
FormControl.setEnabled
Enables or disables the form control.
FormControl.setFocus
Sets the focus to the form control.
FormControl.setFont
Sets the default font for the text of the form control.
FormControl.setForegroundColor
Sets the foreground color of the form control.
FormControl.setMaxSize
Sets the maximum size of a form control.
FormControl.setMinSize
Sets the minimum size of a form control.
FormControl.setPosition
Sets the position of a form control relative to the the form control's parent.
FormControl.setSize
Sets the size of a form control.
FormControl.show
Shows or hides the form control.
FormControl.update
Updates a form control, which will immediately repaint any invalid areas.

Example

// create our own class derived from form
class MyForm extends Form
{
    var m_text1;
    var m_text2;
    
    function MyForm()
    {
        super("Simple Entry", 100, 100, 200, 150);
        
        // create a text control
        m_text1 = new TextBox("", 5, 5, 180, 24);
        this.add(m_text1);
        
        // in m_text1, handle the event that fires when
        // the text is changed, so we can mirror the text
        // in m_text2 (this demonstrates the textChanged event)
        m_text1.textChanged.connect(this, onTextChanged);
       
        // create another text control
        m_text2 = new TextBox("", 5, 35, 180, 24);
        this.add(m_text2);
 
        var b = new Button("Exit", 60, 75, 80, 24);
        this.add(b);
        b.click.connect(this, onButtonClicked);
    }
    
    function onTextChanged(sender, params)
    {
        // set the text in the second control to the text
        // in the first control that has been changed
        m_text2.setText(params.text);
    }
    
    function onButtonClicked()
    {
        // exit the event loop
        Application.exit();
    }
}

// create an instance of our derived MyForm class
// and show it
var f = new MyForm;
f.show();
f = null;

// start the event loop
Application.run();

TextBox.appendText

function TextBox.appendText(text : String)

Arguments

text
The text to append to the existing text in the textbox.

Description

Appends the text, specified by text, to the the existing text of the textbox.

TextBox.clear

function TextBox.clear()

Description

Clears the textbox of all text.

TextBox.getInsertionPoint

function TextBox.getInsertionPoint() : Integer

Returns

Returns the insertion point for the textbox.

Description

Returns the insertion point for the textbox, which is the position in the textbox text where the cursor is located and the index where text will be inserted.

TextBox.getLineCount

function TextBox.getLineCount() : Integer

Returns

Returns the number of lines in the textbox.

Description

Returns the number of lines in the textbox. If the textbox is not a multiline textbox, the function returns 1.

TextBox.getLineLength

function TextBox.getLineLength(line : Integer) : Integer

Returns

Returns the number of characters on a line.

Description

Returns the number of characters on a given line in the textbox.

TextBox.getLineText

function TextBox.getLineText(line : Integer) : String

Returns

Returns the string of text on a given line.

Description

Gets the text on line, specified by line, and returns the the text as a string.

TextBox.getMaxLength

function TextBox.getMaxLength() : Integer

Returns

Returns the maximum number of characters the textbox can have.

Description

Returns the maximum number of characters the textbox can have. If the textbox doesn't have a maximum length, the function returns 0.

TextBox.getPasswordMode

function TextBox.getPasswordMode() : Boolean

Returns

Returns true if the password mode is on for the textbox, and false otherwise.

Description

When a textbox is in password mode, the text is substituted with a non-descript character such as an asterisk so that the text can't be read. This function returns true if password mode is on for the textbox, and false if the password mode is off.

TextBox.getSelectedText

function TextBox.getSelectedText() : String

Returns

Returns the selected text in the textbox.

Description

Gets the selected text in the textbox and returns it as a string.

TextBox.getText

funciton TextBox.getText() : String

Returns

Returns the text of the textbox.

Description

Gets the text of the textbox.

TextBox.isMultiline

function TextBox.isMultiline() : Boolean

Returns

Returns true if the textbox multiline mode is on and false if it is turned off.

Description

Returns true if the textbox multiline mode is on and false if it is turned off.

TextBox.select

function TextBox.select(index : Integer, count : Integer)

Arguments

index
The index of the character to start the selection.
count
The number of characters to select.

Description

Selects text in the textbox, starting at the position specified by index and continuing for the number of characters specified by count.

TextBox.selectAll

function TextBox.selectAll()

Description

Selects all the text in the textbox.

TextBox.setInsertionPoint

function TextBox.setInsertionPoint(index : Integer)

Arguments

index
The index of the character in the textbox where the insertion point should be positioned

Description

Sets the insertion point in the textbox to the offset given by index. The insertion point is the position in the textbox text where the cursor is located and the index where text will be inserted.

TextBox.setMaxLength

function TextBox.setMaxLength(length : Integer)

Arguments

length
The maximum number of characters the texbox can have.

Description

Sets the maximum number of characters the textbox can have to length.

TextBox.setMultiline

function TextBox.setMultiline()
function TextBox.setMultiline(flag : Boolean)

Arguments

flag
A flag to turn the textbox multiline mode on or off.

Description

Sets the multiline mode of the textbox. If flag is true, then the textbox multiline mode will be turned on, causing the textbox text to wrap. If flag is false, then the textbox multiple mode will be turned off, so that the textbox text will not wrap.

TextBox.setPasswordMode

function TextBox.setPasswordMode(flag : Boolean)

Arguments

flag
A flag to turn the password mode on (true) or off (false).

Description

When a textbox is in password mode, the text is substituted with a non-descript character such as an asterisk so that the text can't be read. This function turns the password mode on if flag is true and off if flag is false.

TextBox.setText

function TextBox.setText(text : String)

Arguments

text
The text to which to set the textbox text.

Description

Sets the text for the textbox from text.