Passing different font type strings into RichTextBox?

vamshivemula

New member
Joined
Feb 25, 2010
Messages
3
Programming Experience
1-3
I have situation where I have to retrieve different fields from Access Database and put into one RichTextBox but they have to be displayed as DIFFERENT font types/colors.

I am able to get the database field data into RichTextBox but not able to set font styles or font colors. They are displayed in default font style. Please help me with sample code by giving example, i.e., taking two to three different string types and sending them to RichTextBox with different font color and styles.
 
VB.NET:
 Private Sub ChangeRichTextBoxSelection()
        RichTextBox1.SelectionColor = Color.Blue
        RichTextBox1.SelectionFont = New Font(System.Drawing.FontFamily.Families(5), 12, FontStyle.Bold, GraphicsUnit.Point)

    End Sub

After the strings are in the RichTextBox, you can use .Select() method to select the text that you want to change. Then you can use the .SelectedColor, .SelectedFont properties of the richtextbox instance to change the color and font.
 
Back
Top