Change text colour in textbox

Hi,

I'd like to change the coulr of the text in my text box.  I have two buttons, and a multiline textbox.  When I click button1 text is appended to the textbox as follows:

textbox1.text &= "something"

then when button2 is clicked:

textbox1.text &= "something else"

I would like to make the text generated from button2 to be in red.  But not to change the black text generated from button1.  Is this possible?

Thanks guys.
jakekulaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Fahad MukhtarConnect With a Mentor Distinguished EngineerCommented:
dim s as string
s = "something"
richTextBox1.Text += s                       
richTextBox1.Select(richTextBox1.Text.Length - s.Length   , s.Length)
richTextBox1.SelectionColor = Color.Red
0
 
razoCommented:
u could use a richtext box but when u get back the output it would be either in html or rtf so u have to extract tags to get the orginal text
a regular textbox can't handle this issue
0
 
jakekulaAuthor Commented:
Oh no...  this must be a VB issue, I've seen it done in Java, but there was a fair amount of coding behind it (a whole class actually)...
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Fahad MukhtarDistinguished EngineerCommented:
Textbox is not suitable for that , better use richtext.. it wont include too much code as in the case of java..

you can manipulate the colorsettings using :

RichTextBox1.SelectionStart = 7
RichTextBox1.SelectionLength = 14
RichTextBox1.SelectionColor = Color.Red  
0
 
rohanpandyaCommented:
it is not possible for the ordinary textbox but it is possible in richtextbox
Hi do following

   Dim test As String = "Hello"
            txtRich.Text = txtRich.Text + test
            txtRich.Select(2, test.Length)
            txtRich.SelectionColor = System.Drawing.Color.Red
0
 
waterhiddenCommented:



Me.TextBox1.Attributes.Add("style", "color: #FF0000")

0
 
y1381Commented:
you could try to create a user control inehireted from a richtextbox to do this also ..

hth

--yatharth
0
All Courses

From novice to tech pro — start learning today.