Formatting a RichTextbox in vb (.net)

Notes on how to format richtextbox in vb.net

Dim Position As Int16 = 0
Position += string1.Length
rtb.SelectedText = string1
Dim string1 As String = “This is string1. Font=Arial: FontSize=14: Color=Blue” & vbNewLine
Dim myFont As New Font(“Arial”, 14, FontStyle.Regular, GraphicsUnit.Point)
Dim myColor As Color = Color.Blue
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Position += string1.Length
‘ String 2
string1 = “This is string2. Font=microsoft sans serif: FontSize=10: Color=Red” & vbNewLine
myFont = New Font(“microsoft sans serif”, 10, FontStyle.Regular, GraphicsUnit.Point)
myColor = Color.Red
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Position += string1.Length

‘ String 3
string1 = “This is string3. Font=courier new: FontSize=30: Color=Green: BOLD” & vbNewLine
myFont = New Font(“courier new”, 30, FontStyle.Bold, GraphicsUnit.Point)
myColor = Color.Green
rtb.Select(Position, 0)
rtb.SelectionFont = myFont
rtb.SelectionColor = myColor
rtb.SelectedText = string1
Postion += string1.Length

This Clip was sourced from http://www.daniweb.com/forums/thread98273.html

Leave a Reply

Your email address will not be published. Required fields are marked *