wxTextCtrl text-highlight 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
Rakan
Earned a small fee
Earned a small fee
Posts: 18
Joined: Wed Feb 27, 2008 11:00 pm

wxTextCtrl text-highlight

Post 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
Rakan
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

No, You can try wxStyledTextCtrl or wxRichTextCtrl
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post 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
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

for this under Windows wxTE_RICH style is required
Post Reply