• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Change text colour in textbox


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.
1 Solution
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
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)...
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  
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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
Fahad MukhtarDistinguished EngineerCommented:
dim s as string
s = "something"
richTextBox1.Text += s                       
richTextBox1.Select(richTextBox1.Text.Length - s.Length   , s.Length)
richTextBox1.SelectionColor = Color.Red

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

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


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now