Reputation:
void TestFrame::UpdateStatusBar(wxString color, wxString message)
{
wxStatusBar* bar = wxFrame::GetStatusBar();
bar->SetStatusText("", 0);
wxStaticText* txt = new wxStaticText(bar, wxID_ANY, wxT(""), wxPoint(10, 5), wxDefaultSize, 0);
bar->SetForegroundColour(wxColour(color));
txt = new wxStaticText(bar, wxID_ANY, message, wxPoint(10, 5), wxDefaultSize, 0);
txt->Show(true);
}
Expected behavior
Clear previous status bar text. Add new text to statusbar
Actual behavior
The text is not cleared, new text is added on top and previous text overflows.
Upvotes: 1
Views: 821
Reputation: 7198
This shoukd be enough:
void TestFrame::UpdateStatusBar(wxString color, wxString message)
{
wxStatusBar* bar = GetStatusBar();
bar->SetForegroundColour(wxColour(color));
bar->SetStatusText(message, 0); //text in field 0
}
Notice that I deleted wxFrame::
from GetStatusBar() because your TestFrame
derives from wxFrame
.
You can add a wxStaticText
)or other controls) to the status bar. But this requires to handle size-event for the status bar on your own and position the added control-
Upvotes: -1
Reputation: 960
Each time you create a new wxStaticText with your wxStatusBar as the parent, rather than modifying any of the existing text fields you are creating an additional text object and setting the status bar as its parent. These will then persist until they are deleted.
You should be using bar->SetStatusText or bar->PushStatusText when you want to change the text of a particular existing field in the status bar.
Upvotes: 2