Hi Alan,
Have you considered Richard's suggestion on Redirect the Console's output
to our custom Writer? Here is a simple demo I built through Richard's
suggestion which redirect the "Console" output to the Main Winform, just as
the console:
======================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
namespace GUIConsoleApp
{
public class GUIConsoleForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtConsole;
private System.ComponentModel.Container components = null;
private GUIConsoleWriter writer = null;
public GUIConsoleForm()
{
InitializeComponent();
writer = new GUIConsoleWriter(this);
Console.SetOut(writer);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public void WriteLine(string str)
{
txtConsole.Text = txtConsole.Text + System.Environment.NewLine + str;
txtConsole.SelectionStart=this.txtConsole.Text.Length;
txtConsole.ScrollToCaret();
}
#region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
private void InitializeComponent()
{
this.txtConsole = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.txtConsole.BackColor =
System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)),
((System.Byte)(64)));
this.txtConsole.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtConsole.ForeColor = System.Drawing.Color.White;
this.txtConsole.Location = new System.Drawing.Point(0, 0);
this.txtConsole.Multiline = true;
this.txtConsole.Name = "txtConsole";
this.txtConsole.ReadOnly = true;
this.txtConsole.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtConsole.Size = new System.Drawing.Size(544, 317);
this.txtConsole.TabIndex = 0;
this.txtConsole.Text = "";
this.txtConsole.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.txtConsole_MouseDown);
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlDarkDark;
this.ClientSize = new System.Drawing.Size(544, 317);
this.Controls.Add(this.txtConsole);
this.Name = "GUIConsoleForm";
this.Text = "GUIConsole";
this.Load += new System.EventHandler(this.GUIConsoleForm_Load);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new GUIConsoleForm());
}
private void GUIConsoleForm_Load(object sender, System.EventArgs e)
{
Console.WriteLine("Form Load!");
}
private void txtConsole_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
Console.WriteLine("MouseDown at (" + e.X + " , " + e.Y + ")");
}
}
class GUIConsoleWriter : TextWriter
{
GUIConsoleForm _console;
public GUIConsoleWriter(GUIConsoleForm console)
{
this._console = console;
}
public override Encoding Encoding
{
get{ return null; }
}
public override void Close()
{
_console.Visible = false;
base.Close();
}
public override void WriteLine(string s)
{
_console.WriteLine(s);
}
}
}
==========================================
Hope helps. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)