Color control of text in a text box

C

colin

Hi,
I have a text box wich I would like to
change the color of some of the text,
preferably with text commands,
like with some terminal protocols.

Am I right in thinking the text box doesnt have this
built in and if so is there an easy way to add it
or is there another control wich does it already ?

I dont want to go to somethign realy realy complicated like an html window

Colin =^.^=
 
N

Nicholas Paldino [.NET/C# MVP]

Colin,

You might want to look at the RichTextBox class, which will allow you to
specify different colors for different segments of text. You are right, the
regular TextBox class won't let you do what you want.
 
C

colin

Nicholas Paldino said:
Colin,

You might want to look at the RichTextBox class, which will allow you
to specify different colors for different segments of text. You are
right, the regular TextBox class won't let you do what you want.

Cool thanks, I did just start looking at that,
but from first glance it doesnt seem as though
I can just set the color by putting a tag in the text
or can I ?

its so long since I did this with a terminal I cant remember
what the commands even looked like,
I think it used an escape sequence wich varied
drasticaly from one terminal to another.

Colin =^.^=
 
N

Nicholas Paldino [.NET/C# MVP]

Colin,

No, with the RichTextBox, you will basically have to write the RTF
markup yourself, and set the RTF property, or you will have to select the
text you want to change, and then set the Selection* properties for the
selected text you want to change the properties of.
 
C

colin

Nicholas Paldino said:
Colin,

No, with the RichTextBox, you will basically have to write the RTF
markup yourself, and set the RTF property, or you will have to select the
text you want to change, and then set the Selection* properties for the
selected text you want to change the properties of.
ok thanks, ive tried an html box,
I have to write it to a file i think but
it might be easier I got it to work,

i just need to rember
the codes and such ages since i did raw html,
I got the colors and set a fixed font text but just need to make sure the
indent is kept, and so too are my < characters lol

Colin =^.^=
 
N

Nicholas Paldino [.NET/C# MVP]

Colin,

Some pointers:

- When creating the HTML, you might want to create a style element which
contains the styles for different elements in your HTML. For example, a
certain code would have a certain color. Then, you wrap those elements in
<div> tags (or <span>) and set the class to the class defined in the style
element. This will make changing particular elements easier.

- You can use the static HtmlEncode method on the HttpUtility class in the
System.Web namespace to HTML encode your text. This way, you don't have to
worry about special characters and the like, it's taken care of for you.
 
C

colin

Nicholas Paldino said:
Colin,

Some pointers:

- When creating the HTML, you might want to create a style element which
contains the styles for different elements in your HTML. For example, a
certain code would have a certain color. Then, you wrap those elements in
<div> tags (or <span>) and set the class to the class defined in the style
element. This will make changing particular elements easier.

- You can use the static HtmlEncode method on the HttpUtility class in the
System.Web namespace to HTML encode your text. This way, you don't have
to worry about special characters and the like, it's taken care of for
you.

yay thanks think ive sussed it now, the HttpUtility is useful
for coping with < etc in text at least and i can use the <pre> </pre>
tags wich allow me to keep my spaces.

its a structure data dump something like this :-

fire.engine.name<String>="big red"
.size<Int32>=100
.flames<enum>="High"


where the types like string are in diferent color and the values in another
color

its only for debug, might be nice to put it as a tree but its huge,
generates a million lines for some of the large files
surprisingly quick to read in the whole file and display it
like this.


Colin =^.^=
 
C

colin

Nicholas Paldino said:
Colin,

Some pointers:

- When creating the HTML, you might want to create a style element which
contains the styles for different elements in your HTML. For example, a
certain code would have a certain color. Then, you wrap those elements in
<div> tags (or <span>) and set the class to the class defined in the style
element. This will make changing particular elements easier.

- You can use the static HtmlEncode method on the HttpUtility class in the
System.Web namespace to HTML encode your text. This way, you don't have
to worry about special characters and the like, it's taken care of for
you.

HtmlEncode worked fine but the HtmlDecode method didnt seem to work, I
wanted to see the width
of a string but after id added the colour info,
but it returned the string unchanged,
maybe it needs more tags i just had to do it manualy taking out the stuff id
put in

obviously a change in structure might be called for
but it does what i want now, and its only debug
although it does give me an idea to put it in collapsable html cells
wich would make tree viewing quite nice to be able to do outside the
application.

http://gallery.totalformat.com/showfull.php?photo=120061

COlin =^.^=
 
C

colin

Nicholas Paldino said:
Colin,

Some pointers:

- When creating the HTML, you might want to create a style element which
contains the styles for different elements in your HTML. For example, a
certain code would have a certain color. Then, you wrap those elements in
<div> tags (or <span>) and set the class to the class defined in the style
element. This will make changing particular elements easier.

- You can use the static HtmlEncode method on the HttpUtility class in the
System.Web namespace to HTML encode your text. This way, you don't have
to worry about special characters and the like, it's taken care of for
you.

I might look at style sheets if I had some spare time,
but for now its looking ok, I can see by color
the items in my dump are field names<black>,
feild types <blue>
field values<green>
or <red> for abnormal things like null references
or exceptions that were handled.

some of the dumps are 500k lines
over 10mb, notpad just gives it the thumbs up and luaghs at files that size,
so moving to html was good move.

the web control actually seems a bit faster to load than the
plain text control for text this size.

I only wish I could do the same colour control on my debugger output
Im sure this isnt possible unlees im mistaken ?

thanks
Colin =^.^=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top