Page 1 of 1

A wierd problem! SetForegroundColour etc.

Posted: Thu Jun 19, 2008 1:44 pm
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

Posted: Thu Jun 19, 2008 1:52 pm
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.

Posted: Thu Jun 19, 2008 2:12 pm
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).

Posted: Thu Jun 19, 2008 2:25 pm
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.

Posted: Thu Jun 19, 2008 2:42 pm
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!

:)