1

、およびファイルからのStreamReader読み取りがあります。読み取ったものを変数に保存し、この変数を問題に出力します 。問題は、私が黒で、が緑であるため、ファイル内のテキストの色が黒の場合、TextBox では表示されず、 TextBox で指定した Font は使用されないことに注意してください。.txt.rtf.docxstringRichTextBoxRichTextBox BackColorForeColor.rtf

RichTextBoxではなく、通常のTextBoxを使用することもできますが、そのようにすると、TextBox内のテキストに色を付けることができなくなります...

どうすればそれを修正できますか?

4

1 に答える 1

1

One possibility would be to have a second, invisible, RichTextBox on the form. Read the RTF from the StreamReader, store it in the hidden text box, then read the text from the hidden text box and write it to the visible one. Something like:

string rtfText = File.ReadAllText(filename);
hiddenTextBox.Rtf = rtfText;
visibleTextBox.Text = hiddenTextBox.Text;

Not exactly elegant, but it handles the nasty work of stripping the formatting for you.

于 2012-07-18T02:41:14.573 に答える