Oh Dear

Changing the background colour of a StatusBar on Windows seems pointless - has no effect. I'd assume the control drawing routines take a background colour based on theme or system element. Etc.

Looks like you would need some custom StatusBar drawing if you wanted to achieve this. Or maybe add a control that you could change the background colour of.

Mark

On 04/04/2011 22:37, Mark Dootson wrote:
Hi,

Changing background colour does not automatically cause a window refresh
or repaint. It appears it does on Linux in this case. But that's an
exception / effect you should not rely on.

To have any window redraw and reflect your updates for background colour

$frame->{statusbar}->SetBackgroundColour($color);
$frame->{statusbar}->Refresh;

if you want the changes to appear without waiting for the event loop
$frame->{statusbar}->Update;

btw , you can call

$frame->GetStatusBar->Refresh;
rather than hanging on to a ref to the status bar.

Personally, I always do an explicit 'Refresh' after changing things that
affect the window appearance, even if on some platforms it appears not
to be necessary.

Regards

Mark


On 04/04/2011 22:22, Bruce Ravel wrote:

Hi,

I continue to be surprised by small differences in behavior on linux
and Windows.

This time, the thing I'd like to do is to change the background color
of a StatusBar to indicate how urgently the status message should be
considered by the user. In the following script, I try to change the
StatusBar background using a callback attached to a RadioBox. This
works as I expect on Linux -- the StatusBar changes to ugly green and
red colors when those buttons are clicked. On Windows, however,
nothing happens. The callback is called, but the StatusBar background
color is unchanged.

Am I misunderstanding something about how the StatusBar is intended to
be used? Or about how it is implemented on Windows?

Thanks again!
Bruce



#!/usr/bin/perl
package MyApp;
use base 'Wx::App';
use Wx qw(:everything);
use Wx::Event qw(EVT_RADIOBOX);

sub OnInit {
my $frame = Wx::Frame -> new(undef, -1, 'demo', [-1,-1], [250,150]);
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$frame->{statusbar} = $frame->CreateStatusBar;
$frame->{radio} = Wx::RadioBox->new($frame, -1, "Colors",
wxDefaultPosition, wxDefaultSize,
['normal', 'green', 'red']);
$sizer -> Add($frame->{radio}, 0, wxALL 5);
$frame->{radio} -> SetSelection(0);
EVT_RADIOBOX($frame, $frame->{radio}, \&change_color);

$frame -> SetSizer($sizer);
$frame->{statusbar} -> PushStatusText("Started!");
$frame -> Show(1);
1;
};

sub change_color {
my ($frame, $event) = @_;
my $choice = $frame->{radio}->GetSelection;
my $color = ($choice == 1) ? Wx::Colour->new(0, 255, 0)
: ($choice == 2) ? Wx::Colour->new(255, 0, 0)
: wxNullColour;
$frame->{statusbar} -> SetBackgroundColour($color);
};

package main;
use Wx qw(:everything);
my $app = MyApp->new->MainLoop;






Reply via email to