Re: Text color in wxEuphoria

new topic     » goto parent     » topic index » view thread      » older message » newer message
xfox26 said...

How can I add colors to text in a "wxTextCtrl"?

I have tried a lot of different things, but I could not set the text in colors.

You need to use set_text_style() along with a wxTextAttr object.

include wxeud.e 
 
constant main = create( wxFrame, {0, -1, "Client", -1, -1, 700, 400, wxDEFAULT_FRAME_STYLE} ) 
constant textbox = create( wxTextCtrl , {main, -1, "", -1, -1, -1, -1, wxTE_MULTILINE + wxTE_READONLY } ) 
 
constant ATTRS= { 
	create( wxTextAttr, {} ), 
	create( wxTextAttr, {} ), 
	create( wxTextAttr, {} ) } 
 
set_text_attr_color( ATTRS[1], create( wxColour, {"Black"}) ) 
set_text_attr_color( ATTRS[2], create( wxColour, {"Red"}) ) 
set_text_attr_color( ATTRS[3], create( wxColour, {"Blue"}) ) 
 
constant lines = { 
	"This text in BLACK\n", 
	"This text in RED\n", 
	"This text in BLUE\n" } 
 
integer start, finish 
start = 0 
finish = 0 
for i = 1 to length(lines) do 
	finish += length( lines[i] ) 
	append_text(textbox, lines[i]) 
	set_text_style( textbox, start, finish, ATTRS[i] ) 
	start += length( lines[i] ) 
end for 
 
wxMain( main ) 

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu