Torben L.
Torben L.

Reputation: 73

Save string with color into RTF?

I have a Method that takes a string and converts it into rtf.
You can also set the font-type, -style and -size.
For that i am using a RichTextBox.
Now i have the problem that this Method also has to convert the Color of the Text into rtf.
The RichTextBox does have the property .ForeColor but the color seems not to be in the resolving rtf-string.

Currently the Method looks like this:

private static string ConvertToRtf(string text, 
                                   string fontFamilyName, 
                                   FontStyle fontStyle, 
                                   int fontSize) {
    System.Windows.Forms.RichTextBox richTextBox = 
        new System.Windows.Forms.RichTextBox();

    richTextBox.Font = new Font(new FontFamily(fontFamilyName), 
                                fontSize, 
                                fontStyle, 
                                GraphicsUnit.Point);

        richTextBox.Text = text;
        string result = richTextBox.Rtf;

        return result;
    }

And as mentioned i would like to Convert the Color, too.

Upvotes: 0

Views: 1383

Answers (1)

Link
Link

Reputation: 1711

The RichTextBox has a function for that: RichTextBox.SaveFile

Upvotes: 1

Related Questions