How To Create Rich Text To Fill A RichTextBox

Here's an example of how to fill a rich text box control with formatted text, on-the-fly, in VB.Net. I've been fiddling about for, ooh, literally minutes, trying to find out how to do this. The Internet seems sparse when it comes to examples of how to do it.

I have a RichTextBox control on my form called rt.

With rt
	.Clear()

	.SelectionFont = New Font(.Font.FontFamily, 12, FontStyle.Underline)
	.AppendText("Rich Text Demo" & vbCrLf)

	.SelectionFont = New Font(.Font.FontFamily, 8, FontStyle.Bold)
	.AppendText("Some Bold Text" & vbCrLf)

	.SelectionFont = New Font(.Font.FontFamily, 8, FontStyle.Regular)
	.AppendText("Here is some normal text.  And a bit of ")

	.SelectionFont = New Font(.Font.FontFamily, 8, FontStyle.Italic)
	.AppendText("italic")

	.SelectionFont = New Font(.Font.FontFamily, 8, FontStyle.Regular)
	.AppendText("text too.")

End With
		

And here's how it looks:

Rich text example VB.Net
Page Updated 06/02/09