Re: Colored words in textbox
Textbox can only change the color of the whole text. Use RichTextBox if you need colored words.
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
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
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?
Re: Colored words in textbox
Quote:
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.
Re: Colored words in textbox
I see.. Thank you cicatrix
Re: Colored words in textbox
Quote:
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):confused:
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
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)