|
-
Jan 28th, 2010, 05:08 AM
#1
Thread Starter
Lively Member
Colored words in textbox
hey guys, well I was wondering if there's anyway to color stuff in a textbox?
example:
I have a big textbox and if I type hi in that textbox I want that text to become grey, and if I type bye I want the text to become red, any ideas?
btw, I took your advice from my latest thread and installed a stable version of 2005 
I did some thinking and come up with the idea "if textbox1.text ="hej" then" set a color but then I realized the whole text would become to coded text, hmm..
Last edited by macbrutal; Jan 28th, 2010 at 05:11 AM.
Reason: Thoughts
-
Jan 28th, 2010, 05:15 AM
#2
Re: Colored words in textbox
Textbox can only change the color of the whole text. Use RichTextBox if you need colored words.
-
Jan 28th, 2010, 06:13 AM
#3
Thread Starter
Lively Member
Re: Colored words in textbox
Cicatrix, thank you for the reply!
Please define your idea, so if I replace my textbox to a RTF what should I do next? I've tried to google this, but can't find any codes/explainations
-
Jan 28th, 2010, 06:41 AM
#4
Re: Colored words in textbox
vb.net Code:
' Put a RichTextBox control on a form and name it RichTextBox1 Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load RichTextBox1.Text = "My text. This is a blue text. This is a red text." Dim pos As Integer = RichTextBox1.Find("blue text") With RichTextBox1 .Select(pos, "blue text".Length) .SelectionColor = Color.Blue pos = .Find("red text") .Select(pos, "red text".Length) .SelectionColor = Color.Red End With End Sub
-
Jan 28th, 2010, 08:35 AM
#5
Thread Starter
Lively Member
Re: Colored words in textbox
Cicatrix, thank you for the reply once again but I don't think we get each other 
If I type "hello" in this RTF I want all the hello's to be red and if I type "bye" I want all the "bye's" to be blue if you know what I mean?
-
Jan 28th, 2010, 09:05 AM
#6
Re: Colored words in textbox
 Originally Posted by macbrutal
Cicatrix, thank you for the reply once again but I don't think we get each other 
If I type "hello" in this RTF I want all the hello's to be red and if I type "bye" I want all the "bye's" to be blue if you know what I mean?
It can't be done automatically. I showed you the principles involved.
In your case you should catch a TextChanged event of your richtextbox and do the search for your hello and bye strings and change their colors.
Last edited by cicatrix; Jan 28th, 2010 at 09:20 AM.
-
Jan 29th, 2010, 06:01 AM
#7
Thread Starter
Lively Member
Re: Colored words in textbox
I see.. Thank you cicatrix
-
Aug 1st, 2010, 06:39 AM
#8
Lively Member
Re: Colored words in textbox
 Originally Posted by cicatrix
vb.net Code:
' Put a RichTextBox control on a form and name it RichTextBox1
Public Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RichTextBox1.Text = "My text. This is a blue text. This is a red text."
Dim pos As Integer = RichTextBox1.Find("blue text")
With RichTextBox1
.Select(pos, "blue text".Length)
.SelectionColor = Color.Blue
pos = .Find("red text")
.Select(pos, "red text".Length)
.SelectionColor = Color.Red
End With
End Sub
please how to change to between bold/normal?
because .SelectionFont.Bold = True doesn't work (read only)
-
Aug 1st, 2010, 02:42 PM
#9
Re: Colored words in textbox
You can't change it this way, you must assign a new font.
Code:
With RichTextBox1
' ...
.SelectionFont = New Font(.Font.FontFamily, .Font.Size, FontStyle.Bold)
' ...
End With
-
Aug 2nd, 2010, 09:00 AM
#10
Lively Member
Re: Colored words in textbox
thanks.
wonder why is not implemented in an easy way.
if I can change only bold or italic.
oh! sure! an language with easy sentences are not so proffesional...
(sorry I can't give you the rate because maybe my last was also for you)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|