If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
-
Double Trouble
- Knows some wx things

- Posts: 26
- Joined: Sat Jun 14, 2008 12:42 pm
- Location: Sweden
-
Contact:
Post
by Double Trouble » Thu Jun 19, 2008 1:44 pm
Hi!
I've run in to a weird problem here in my OnSub-function. The first part works perfect but the else-part just won't work! I get no errors but the color change doesn't happen. If I put that line in the constructor instead it works perfectly.
I've declared panel in the class and so on...
Code: Select all
void Window::OnSub(wxCommandEvent & WXUNUSED(event))
{
inword = userin->GetValue();
corline = getstring(k+1);
if(inword.CmpNoCase(corline) == 0)
{
userin->Clear();
k = p*(rand() % nwords + 1) - 2;
st->SetLabel( getstring(k) );
userin->SetFocus();
}
else
{
panel->SetForegroundColour(*wxRED);
}
}
Can you spot something that might be wrong?
Thank you in advance!
/DT
-
doublemax
- Moderator

- Posts: 15496
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Post
by doublemax » Thu Jun 19, 2008 1:52 pm
a wxPanel doesn't really have a foreground color, it just happens that the wxStaticText will inherit that color, if you add it to the panel after setting the color.
If you want to change the color of the wxStaticText, you should use st->SetForegroundColour().
Eventually you may need a st->Refresh() to make the change visible.
Use the source, Luke!
-
Double Trouble
- Knows some wx things

- Posts: 26
- Joined: Sat Jun 14, 2008 12:42 pm
- Location: Sweden
-
Contact:
Post
by Double Trouble » Thu Jun 19, 2008 2:12 pm
doublemax wrote:a wxPanel doesn't really have a foreground color, it just happens that the wxStaticText will inherit that color, if you add it to the panel after setting the color.
If you want to change the color of the wxStaticText, you should use st->SetForegroundColour().
Eventually you may need a st->Refresh() to make the change visible.
Thank you, that worked!
But just out of curiosity. When i put the line
Code: Select all
panel->SetForegroundColour(*wxRED);
in the constructor it works just as I want (the color change of the static text).
-
doublemax
- Moderator

- Posts: 15496
- Joined: Fri Apr 21, 2006 8:03 pm
- Location: $FCE2
Post
by doublemax » Thu Jun 19, 2008 2:25 pm
Double Trouble wrote:But just out of curiosity. When i put the line
Code: Select all
panel->SetForegroundColour(*wxRED);
in the constructor it works just as I want (the color change of the static text).
read my first line. The wxStaticText will inherit the wxPanel's foreground color when you create it.
Use the source, Luke!
-
Double Trouble
- Knows some wx things

- Posts: 26
- Joined: Sat Jun 14, 2008 12:42 pm
- Location: Sweden
-
Contact:
Post
by Double Trouble » Thu Jun 19, 2008 2:42 pm
doublemax wrote:Double Trouble wrote:But just out of curiosity. When i put the line
Code: Select all
panel->SetForegroundColour(*wxRED);
in the constructor it works just as I want (the color change of the static text).
read my first line. The wxStaticText will inherit the wxPanel's foreground color when you create it.
Ah, sorry! Thank you for making it clear!
