Package Win32::GUI::Textfield

Back to the Packages


Constructor

new Win32::GUI::Textfield(PARENT, %OPTIONS)

Creates a new Textfield object; can also be called as PARENT->AddTextfield(%OPTIONS). Class specific %OPTIONS are:

  -align         => left/center/right (default left)
      aligns the text in the control accordingly.
  -keepselection => 0/1 (default 0)
      the selection is not hidden when the control loses focus.
  -multiline     => 0/1 (default 0)
      the control can have more than one line (note that newline
      is "\r\n", not "\n"!).
  -password      => 0/1 (default 0)
      masks the user input (like password prompts).
  -passwordchar  => char (default '*')
      the char that is shown instead of the text with -password => 1.
  -prompt        => (see below)
  -readonly      => 0/1 (default 0)
      text can't be changed.

The -prompt option is very special; if a string is passed, a Win32::GUI::Label object (with text set to the string passed) is created to the left of the Textfield. Example:

    $Window->AddTextfield(
        -name   => "Username",
        -left   => 75,
        -top    => 150,
        -prompt => "Your name:",
    );

Furthermore, the value to -prompt can be a reference to a list containing the string and an additional parameter, which sets the width for the Label (eg. [ STRING, WIDTH ] ). If WIDTH is negative, it is calculated relative to the Textfield left coordinate. Example:

    -left => 75,                          (Label left) (Textfield left)
    -prompt => [ "Your name:", 30 ],       75           105 (75+30)
    -left => 75,
    -prompt => [ "Your name:", -30 ],      45 (75-30)   75

Note that the Win32::GUI::Label object is named like the Textfield, with a ``_Prompt'' suffix (in the example above, the Label is named ``Username_Prompt'').


Methods

LineFromChar(INDEX)

Returns the line where the zero-based INDEX char appears.

MaxLength([CHARS])

Limits the number of characters that the Textfield accept to CHARS, or returns the current limit if no argument is given. To remove the limit (eg. set it to the maximum allowed which is 32k for a single-line Textfield and 64k for a multiline one) set CHARS to 0.

Modified([FLAG])

Gets or sets the modified flag on the textfield.

PasswordChar([CHAR])

Gets or sets the character displayed in place of normal text; if the Textfield has been created with the -password option, the default character is an asterisk (*). Note that by setting this value the text in the textfield will be redrawn using the specified character; if the character is set to zero instead, text will be redrawn as normal

ReadOnly([FLAG])

Gets or sets the readonly flag on the textfield.

ReplaceSel(STRING, [FLAG])

Replaces the current selection in the Textfield with STRING.

Select(START, END)

Selects the specified range of characters in the Textfield.

SelectAll()

Selects all the text in the Textfield.

Undo()

Undoes the last change in the textfield.


Events

Change()

Sent when the text in the field is changed by the user.

GotFocus()

Sent when the control is activated.

LostFocus()

Sent when the control is deactivated.