By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Different colored lines in the same textbox

P: n/a
How do i write lines with different colors in a textbox?
I've tried using the forecolor property and it just takes the last
color.
eg.
TextBox1.ForeColor = Color.Red
TextBox1.Text = "test" & " "
TextBox1.ForeColor = Color.Purple
TextBox1.Text &= "test2"

It prints both test and test2 in purple

Mar 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"None" <sh**********@gmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
How do i write lines with different colors in a textbox?
I've tried using the forecolor property and it just takes the last
color.
eg.
TextBox1.ForeColor = Color.Red
TextBox1.Text = "test" & " "
TextBox1.ForeColor = Color.Purple
TextBox1.Text &= "test2"

It prints both test and test2 in purple


I don't believe this is possible in a default textbox. There are 2 options
I believe you have..

1. use an RTF box instead.
2. Custom Draw your textbox. This would be more work but I think it would
allow you to set the different colors using the graphics.drawxxxx methods.

jjardine
Mar 23 '06 #2

P: n/a
"None" <sh**********@gmail.com> schrieb:
How do i write lines with different colors in a textbox?
I've tried using the forecolor property and it just takes the last
color.
eg.
TextBox1.ForeColor = Color.Red
TextBox1.Text = "test" & " "
TextBox1.ForeColor = Color.Purple
TextBox1.Text &= "test2"

It prints both test and test2 in purple


You may want to use the RichTextBox control instead of the common textbox.
The richtextbox' 'SelectionColor' property can be used to change the color
of the selected text.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.