I need to get the font set in .txt file (or .rtf) before loading it to a richTextBox. If I don’t do this the default font is set and the richTextBox.Text’s font is different than the one set in the original .txt file…
I’m dealing with a custom TextPanel inherited from RichTextBox.
if (File.Exists(file))
{
if (Path.GetExtension(file) == ".txt")
{
// I need to get the font here from the path "file" .txt document
textPanel = new TextPanel(file, this);
textPanel.LoadFile(file, RichTextBoxStreamType.PlainText);
I’m sure there’s a simple way to do this, just can’t find it 🙁
Plain text files don’t store font information. (They’re plain text files, meaning they only store text.) When they’re loaded, they use the font of the container they’re displayed in.
If an actual richtext (
.rtf) file has font information, and it’s loaded as an .rtf file (don’t useRichTextBoxStreamType.PlainText, and useRichTextBoxStreamType.RichTextinstead), theRichTextBoxshould automatically set the font for you with no code involved.