1 public class TextBoxWriter : System.IO.TextWriter
2 {
3 ListBox lstBox;
4 delegate void VoidAction();
5
6 public TextBoxWriter(ListBox box)
7 {
8 lstBox = box;
9 }
public override void Write(string value)
{
VoidAction action = delegate
{
lstBox.Items.Insert(, string.Format("[{0:HH:mm:ss}]{1}", DateTime.Now, value));
};
lstBox.BeginInvoke(action);
}
public override void WriteLine(string value)
{
VoidAction action = delegate
{
lstBox.Items.Insert(, string.Format("[{0:HH:mm:ss}]{1}", DateTime.Now, value));
};
lstBox.BeginInvoke(action);
}
public override System.Text.Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
} void frmMain_Load(object sender, EventArgs e)
{
Console.SetOut(new TextBoxWriter(Instances.ucLog.LogBox));
}