RichTextBox control set document back color

Peter Volz 1,295 Reputation points
2023-07-14T23:50:03.6333333+00:00

Hello all

Visual Studio .Net 2010 project > .Net framework 4.0 Full profile project > WinForms

I need to process Rtf files and ONLY adding a document/page backcolor is needed.

So using RichTextBox I can load it but can't find a Page BG color property, is there any way?

If not, may I manually edit Rtf using File.ReadAllText and inject the Rtf background property? If yes what to insert where? Rtf version is basic, actually parsed from Outlook MapiMessage Rtf body part.

Thanks for the help.

Developer technologies | Windows Forms
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2023-07-15T18:37:24.0233333+00:00

    If I test with a minimal rtf sample like :

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1041{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
    \pard\cf1\f0\fs24 This is a test\par
    \par
    }
    

    I can add a background after the first line,like (16711935 is for Magenta) :

    {\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1041{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
    {\*\background {\sn fillColor}{\sv 16711935}}
    \pard\cf1\f0\fs24 This is a test\par
    \par
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.