Change Font & Color

Started by magesh.p, May 21, 2009, 08:45 PM

Previous topic - Next topic

magesh.p

Change Text & Color when Highlighted

My Code is Below :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FontDialog1.ShowDialog()
RichTextBox1.Font = FontDialog1.Font
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ColorDialog1.ShowDialog()
RichTextBox1.ForeColor = ColorDialog1.Color
End Sub

When I Want to change font and color in richtextbox, All Text in Textbox is Changed.

I Want  that change color and font in text that we highlight.

Help Me,

Thanks in Advance..........

- An Proud Acumen -

VelMurugan

#1
Hi Acumen,

Quote from: magesh.p on May 21, 2009, 08:45 PM
Change Text & Color when Highlighted

My Code is Below :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FontDialog1.ShowDialog()
RichTextBox1.Font = FontDialog1.Font
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ColorDialog1.ShowDialog()
RichTextBox1.ForeColor = ColorDialog1.Color
End Sub

When I Want to change font and color in richtextbox, All Text in Textbox is Changed.

I Want  that change color and font in text that we highlight.

Help Me,

Thanks in Advance..........



The Below Code Is Something Related to your Concepts

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
RichTextBox1.SelectionStart = RichTextBox1.Find("Hi,")
'using the Find method to find the text "are" and setting it's return
'property to SelectionStart which selects the text
RichTextBox1.SelectionColor = Color.Blue
'setting the color for the selected text with SelectionColor property
RichTextBox1.SelectionStart = RichTextBox1.Find("Are")
RichTextBox1.SelectionColor = Color.Yellow
End Sub

Output :


Hi, How Are You

VelMurugan

Quote from: magesh.p on May 21, 2009, 08:45 PM
Change Text & Color when Highlighted

My Code is Below :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FontDialog1.ShowDialog()
RichTextBox1.Font = FontDialog1.Font
End Sub


When I Want to change font and color in richtextbox, All Text in Textbox is Changed.

I Want  that change color and font in text that we highlight.

Help Me,

Thanks in Advance..........



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_As System.EventArgs) Handles Button1.Click
RichTextBox1.SelectionStart = RichTextBox1.Find("How")
'using the Find method to find the text "are" and setting it's
'return property to SelectionStart which selects the text to format
Dim ifont As New Font(RichTextBox1.Font, FontStyle.Italic)
'creating a new font object to set the font style
RichTextBox1.SelectionFont = ifont
'assigning the value selected from the RichTextBox the font style
RichTextBox1.SelectionStart = RichTextBox1.Find("You")
Dim bfont As New Font(RichTextBox1.Font, FontStyle.Bold)
RichTextBox1.SelectionFont = bfont
End Sub


OutPut :

Hi, How Are You