Reputation: 13043
I have a lot of formatted code snippets saved in an XML file. On request I load them and set as Rtf in a RichTextBox:
string cscode = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fprq1\fcharset0 Courier New;}{\f1\fnil\fcharset0..." etc.
rtb_cs.Rtf = cscode;
The code snippets are copy-pasted from the Visual Studio, so the text is colored differently. Different Visual Studios are using different Fonts for the text.
Is there a way to change the Font but keep the colors?
I've tried to set the Font
property of the RichTextBox, but this also resets the colors.
//This changes colors as well
rtb_cs.Font = new Font(FontFamily.GenericSansSerif, 10);
Upvotes: 0
Views: 2331
Reputation: 4408
Take a look at LarsTech's solution here:
Changing font for richtextbox without losing formatting
It works for other settings too.
Upvotes: 1