c++wxwidgets

How to change default color of text in wxRitchTextCtrl


How to change default color of text in wxRitchTextCtrl

Here is my Source code I change foreground color, Default color etc. always i get black color.

ed = new wxRichTextCtrl(panel, wxID_ANY, wxEmptyString, ..., wxVSCROLL);
ed->SetBackgroundColour(wxColour(0, 121, 122));
ed->SetForegroundColour(wxColour(255, 255, 255));

Solution

  • I would try this:

    wxRichTextAttr attr = ed->GetBasicStyle();
    attr.SetBackgroundColour(wxColour(0, 121, 122));
    attr.SetTextColour(wxColour(255, 255, 255));
    ed->SetBasicStyle(attr);
    

    According to the docs, GetBasicStyle() and SetBasicStyle() refer to 'the style of the whole buffer before further styles are applied'. Constructing a copy of the current basic style as a baseline ensures we only change the attributes we want and don't inadvertently change any other defaults.