Page 1 of 1

wxTextCtrl text-highlight

Posted: Tue Apr 29, 2008 9:31 pm
by Rakan
Hello,

I am working on a simple text-editor that would just highlight certain words for me like programming language keyworks, lets say PHP. Does wxTextCtrl support highlighting text in colors, and how?

Thanks,
Rakan

Posted: Tue Apr 29, 2008 9:36 pm
by lester
No, You can try wxStyledTextCtrl or wxRichTextCtrl

Posted: Wed Apr 30, 2008 10:13 am
by DavidHart
Hi,

While those are probably better choices in your case, just for the record you can do this in wxTextCtrl too, using http://docs.wxwidgets.org/stable/wx_wxtextattr.html.
e.g.

Code: Select all

wxTextAttr style; wxFont font;
style = text->GetDefaultStyle(); // Save original style
font = style.GetFont(); // Get default font, & enBolden it
font.SetWeight(wxBOLD );
...
if ( foo )
  {  text->SetDefaultStyle( wxTextAttr(wxNullColour, wxNullColour, font) ); // Turn on Bold
      text->AppendText( bar ); // Add wxString bar to textctrl with Bold font
      text->SetDefaultStyle( style ); // Reset to original style, for future Appends
  }
...
You can change colours too.

Regards,

David

Posted: Wed Apr 30, 2008 10:20 am
by lester
for this under Windows wxTE_RICH style is required