I've created a static text control inside the status bar control so that I can display colored text there like so:
my $status = Wx::StatusBar->new($parent,wxSB_RAISED);
$status->SetForegroundColour(wxRED);
my $warning = Wx::StaticText->new ($status, wxID_ANY,"Input Error!");
But how do I destroy the text control so that I can display status text in the same position without getting blocked?
I've tried:
$warning->Destroy();
$status->SetStatusText("OK",0);
But it does not seem to have any effect. Any pointers? Thanks like always.
UPDATE
Thanks Anonymous Monks :)
I had tried the Hide and Show methods before posting the question but it didn't seem to work. But now after playing around with the demo code you kindly offered here, I think I am able to get the hide and show to work as expected. Thanks :)
But I'm still missing something obvious. The following code shows my problem: why I can't destroy the control?
use strict; use warnings;
use Wx ':everything';
my $window = Wx::Frame->new(undef, -1, "Colored Statusbar Text");
my $panel = Wx::Panel->new($window);
my $button = Wx::Button->new(
$panel,
-1,
"Toggle",
);
Wx::Event::EVT_BUTTON(
$button,
-1,
\&button_click,
);
my $status = $window->CreateStatusBar(2, wxSB_RAISED);
$window->Show;
my $hit =1;
Wx::SimpleApp->new->MainLoop;
sub button_click {
$hit++;
my $warning = Wx::StaticText->new($status, -1, "Input Error",,[3,8
+]);
$warning->SetForegroundColour(wxRED);
if ($hit % 2) {
$status->SetStatusText("", 0);
$warning->Show;
}
else {
$warning->Destroy;
$status->SetStatusText("OK", 0);
}
}
UPDATE2
The hide and show methods seem to work:
use strict; use warnings;
use Wx ':everything';
my $window = Wx::Frame->new(undef, -1, "Colored Statusbar Text");
my $panel = Wx::Panel->new($window);
my $button = Wx::Button->new(
$panel,
-1,
"Toggle",
);
Wx::Event::EVT_BUTTON(
$button,
-1,
\&button_click,
);
my $status = $window->CreateStatusBar(2, wxSB_RAISED);
my $warning = Wx::StaticText->new($status, -1, "Input Error",,[3,8]);
$warning->SetForegroundColour(wxRED);
$window->Show;
my $hit =1;
Wx::SimpleApp->new->MainLoop;
sub button_click {
$hit++;
if ($hit % 2) {
$status->SetStatusText("", 0);
$warning->Show;
}
else {
$warning->Hide;
$status->SetStatusText("OK", 0);
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.