Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How cai I change font color in text?

Status
Not open for further replies.

juhaka

Programmer
Nov 14, 2002
26
FI
Hi!
I'm just writing a very simple XML editor. I have a TextBox instance as a editing panel. How can I change the color of tags? My goal is, that when I press '<' -key (in TextBox), this and the next characters would be blue, and when I press '>' -key, the next characters would be black again.

I have a method, which catch pressed key.

private void keyPressed(object sender, KeyPressEventArgs ex)
{
switch(ex.KeyChar)
{
case '<':
{
this.TBselect.ForeColor = System.Drawing.SystemColors.HotTrack;
break;
}
default:
{
break;
}
}
}


but this changes ALL text.

What should I do, or should I raise my hands up?

br.
Juha K
 
The color of the text in a textbox is all one color -- you can't have a few characters in blue, and the rest in black.

For that you'd need something like the RichText box where you'd select a range of text, then apply formatting to it (like using the SelectionColor property).

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanks, Chip, once again!
I will try it with RichText box....

Juha Ka
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top