Set Backcolor

Peter Volz 1,295 Reputation points
2023-07-15T04:50:20.2566667+00:00

Hello

Need to set a page back color for RTF files, seems that RichTextBox of Visual Studio cannot set document back color.

My RTF files are parsed from Outlook Msg files' RTF bodypart, so I saved 2 messages with and without back color and compared:

After this common command in both versions: ilfomacatclnup0

This is added to the back colored version:

"{\*\background {\shp{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1\shpz0\shplid1025{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn fillColor}{\sv 3506515}}{\sp{\sn fFilled}{\sv 1}}{\sp{\sn lineWidth}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn bWMode}{\sv 9}}{\sp{\sn fBackground}{\sv 1}}{\sp{\sn fLayoutInCell}{\sv 1}}}}}\"

The problem is that when I want to insert this back color string to other RTF files, mostly cannot find "ilfomacatclnup0" so don't know where to String.Insert the back color part to?

Also editing RTF files as text using string manipulation and File.ReadAllText / File.WriteAllText is OK or not?

Thanks :)

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,873 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 114.7K Reputation points
    2023-07-15T12:35:05.1633333+00:00

    I think that it can be inserted just before the last “}” that closes the RTF. The sequence to be inserted is:

    \viewbksp1 {\*\background {\shp{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1\shpz0\shplid1025{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn fillColor}{\sv 3506515}}{\sp{\sn fFilled}{\sv 1}}{\sp{\sn lineWidth}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn bWMode}{\sv 9}}{\sp{\sn fBackground}{\sv 1}}{\sp{\sn fLayoutInCell}{\sv 1}}}}}
    

    Maybe it can be simplified.

    The background seems to be recognized by the RichTextBox control, Word and WordPad editors.

    0 comments No comments