日期:2014-05-18 浏览次数:21122 次
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form1 frm1 = new Form1(); frm1.Show(); Console.Write("abc"); Console.WriteLine("abc"); } public partial class Form1 : Form { public Form1() { InitializeComponent(); ConsoleRedir(); } public void ConsoleRedir() { StringRedir r = new StringRedir(ref textBox1); Console.SetOut(r); } public class StringRedir : StringWriter { private TextBox outBox; public StringRedir(ref TextBox textBox) { outBox = textBox; } public override void WriteLine(string x) { outBox.Text += x + "\r\n"; outBox.Refresh(); } public override void Write(string value) { outBox.Text += value; } } }