Lukebo
Lukebo

Reputation: 35

.net RichTextBox - Set fonts automatically

I have a .net RichTextBox which is filled with a certain report document, my application creates. This report shall then be edited by the user if desired and printed. This works so far but I want to do it a little more "human readable" by formatting certain paragraphs depending on their content automatically (e.g. red bold text for critical events in a certain section).

At the moment, i create a (big) string which is then passed to the box:

Dim Report as String = SubString1 & vbnewline & Substring 2 & vbnewline & .....
RTBox.Text = Report

My question: Is it possible, to assign different fonts/alignments/styles to the substrings, e.g. Substring 1 is right aligned and bold, substing2 is left aligned and italic and so on.

I am aware of the SelectionFont and SelectionColor commands, but they seem to work only for a text fragment, that is currently selected in the box? Any help would be greatly appreciated! Thanks! Luke

Upvotes: 0

Views: 96

Answers (1)

Lukebo
Lukebo

Reputation: 35

Here is a proposal from my further research. Using RTBox.rtf = "...." instead of RTBox.Text="...." one is able to write rtf-code to the box which then displays the document well formatted.

Upvotes: 1

Related Questions