标签:
主要是设置它的Out属性到内存流中,然后再将内存中的流输出到文本框中,这个函数很好理解, 不多解释了.备用
private void Display() { Cursor hold = this.Cursor; this.Cursor = Cursors.WaitCursor; outputTextBox.Text = ""; StreamWriter writer = new StreamWriter(new MemoryStream()); TextWriter oldConsoleOut = Console.Out; Console.SetOut(writer); MemoryStream stream = (MemoryStream)writer.BaseStream; stream.SetLength(0); Console.WriteLine("显示在文本框中,而不是控制台!"); writer.Flush(); Console.SetOut(oldConsoleOut); outputTextBox.Text += writer.Encoding.GetString(stream.ToArray()); this.Cursor = hold; }
结果如下所示:
标签:
原文地址:http://www.cnblogs.com/cang/p/4253518.html