Format Text in RichTextBox Control

Mike_Stevens
Mike_Stevens used Ask the Experts™
on
I am trying to use a rich text box control on a windows form.  I want to be able to give the user the ability to select certain parts of the text that is in the rich text box and change it's color, font size, make it bold, etc.   I am not sure how to do this.

Can anybody shed some light on it for me?

Thanks,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
You can do something similar to:
Private Sub MakeBlueButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If Me.RichTextBox1.SelectedText.Length > 0 Then
        Me.RichTextBox1.SelectionColor = Color.Blue
    End If
End Sub

Private Sub BoldButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If Me.RichTextBox1.SelectedText.Length > 0 Then
        Me.RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont, FontStyle.Bold)
    End If
End Sub

Open in new window

ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
And for completeness, making text bigger would be:
Private Sub MakeBigger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    If Me.RichTextBox1.SelectedText.Length > 0 Then
        Me.RichTextBox1.SelectionFont = New Font(Me.RichTextBox1.SelectionFont.FontFamily, Me.RichTextBox1.SelectionFont.Size + 1, Me.RichTextBox1.SelectionFont.Style)
    End If
End Sub

Open in new window

Author

Commented:
Awesome...thanks
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial