Solved

Change text colour in textbox

Posted on 2004-08-10
7
245 Views
Last Modified: 2010-04-23
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.
0
Comment
Question by:jakekula
7 Comments
 
LVL 8

Expert Comment

by:razo
ID: 11770030
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
 

Author Comment

by:jakekula
ID: 11770058
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
 
LVL 19

Expert Comment

by:Desp
ID: 11770106
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 4

Expert Comment

by:rohanpandya
ID: 11770283
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
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
ID: 11770318
dim s as string
s = "something"
richTextBox1.Text += s                       
richTextBox1.Select(richTextBox1.Text.Length - s.Length   , s.Length)
richTextBox1.SelectionColor = Color.Red
0
 
LVL 2

Expert Comment

by:waterhidden
ID: 11773160



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

0
 
LVL 4

Expert Comment

by:y1381
ID: 11775792
you could try to create a user control inehireted from a richtextbox to do this also ..

hth

--yatharth
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question