4 using System.Windows.Forms;
6 namespace SharpDisplayManager
8 public class RichTextBoxTextWriter : TextWriter
10 public delegate void WriteDelegate(char aChar);
12 RichTextBox iRichTextBox = null;
13 string iAccumulator = "";
15 public RichTextBoxTextWriter(RichTextBox aRichTextBox)
17 iRichTextBox = aRichTextBox;
20 public override void Write(char aChar)
23 if (iRichTextBox.InvokeRequired)
27 iAccumulator += aChar;
30 //WriteDelegate d = new WriteDelegate(Write);
31 //iRichTextBox.Invoke(d, new object[] { aChar });
36 iRichTextBox.AppendText(aChar.ToString()); // When character data is written, append it to the text box.
40 public override Encoding Encoding
42 get { return System.Text.Encoding.UTF8; }
45 public void FlushAccumulator()
49 if (!string.IsNullOrEmpty(iAccumulator))
51 iRichTextBox.AppendText(iAccumulator); // When character data is written, append it to the text box.