A wierd problem! SetForegroundColour etc. Topic is solved

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.
Post Reply
Double Trouble
Knows some wx things
Knows some wx things
Posts: 26
Joined: Sat Jun 14, 2008 12:42 pm
Location: Sweden
Contact:

A wierd problem! SetForegroundColour etc.

Post by Double Trouble »

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
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

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
Knows some wx things
Posts: 26
Joined: Sat Jun 14, 2008 12:42 pm
Location: Sweden
Contact:

Post by Double Trouble »

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).
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

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
Knows some wx things
Posts: 26
Joined: Sat Jun 14, 2008 12:42 pm
Location: Sweden
Contact:

Post by Double Trouble »

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!

:)
Post Reply