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 » Tue Apr 29, 2008 9:31 pm

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 » Tue Apr 29, 2008 9:36 pm

No, You can try wxStyledTextCtrl or wxRichTextCtrl

DavidHart
Site Admin
Site Admin
Posts: 4008
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Wed Apr 30, 2008 10:13 am

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 » Wed Apr 30, 2008 10:20 am

for this under Windows wxTE_RICH style is required

Post Reply