Wx::StaticText
From WxPerl wiki
A static text control displays one or more lines of read-only text.
Contents |
Example
my $text_control = Wx::StaticText->new(
$panel, # parent window
-1, # Let the system assign a window ID
"Hello, World!", # The literal text to display
[10, 25], # [x, y] coordinates of the control
);
To modify the text once created:
$text_control->SetLabel('New text');
Inheritance
Wx::StaticText derives from Wx::Control, Wx::Window, Wx::EvtHandler, and Wx::Object.
Styles
The following symbols are exported (upon request) by Wx.pm, and can be used in the constructor:
- wxALIGN_LEFT — Align the text to the left
- wxALIGN_RIGHT — Align the text to the right
- wxALIGN_CENTRE — Center the text horizontally
- wxST_NO_AUTORESIZE — If set, the control will not change its size automatically when SetLabel is called. (By default, the text control will adjust its size to exactly fit to the size of the text, each time SetLabel is called. This style is especialy useful in combination wtih wxALIGN_RIGHT or wxALIGN_CENTRE, because otherwise they won't make sense any longer after a call to SetLabel.
Constructor
new
$control = Wx::StaticText->new($parent, $id, $text, $pos, $size, $style, $name);
This is the constructor.
Options:
- $parent — The window parent. Should not be undef.
- $id — An integer specifying the window identifier. Usually you will specify -1 to let the system assign a window ID automatically.
- $text — The text to display.
- $pos — The control position, a reference to an array containing an x and a y coordinate.
- $size — The size of the text control, a reference to an array containing a width and a height. The special value [-1, -1] tells the system to use a default size.
- $style — The control style to use (see above). Optional.
- $name — The name of the control. This parameter is used to associate a name with the control, which allows certain windowing systems to search for the control by name.
Create
$control = Wx::StaticText->Create($parent, $id, $text, $pos, $size, $style, $name);
This is a creation function, for two-step construction. The parameters are the same as for the constructor, above.
Methods
GetLabel
$text = $control->GetLabel();
Returns the contents of the control.
SetLabel
$control->SetLabel($text);
Sets the static text label and updates the control's size to exactly fit the label, unless the control has the wx_ST_NO_AUTORESIZE flag.
Wrap
$control->Wrap($width);
This functions wraps the controls label so that each of its lines becomes at most $width pixels wide if possible (the lines are broken at words boundaries so it might not be the case if words are too long). If width is negative, no wrapping is done.
SEE ALSO
See Jouke's tutorial - http://www.perl.com/pub/a/2001/09/12/wxtutorial1.html - for an example of creating and modifying a Wx::StaticText object.
