在不调用Application.Run()的情况下处理RichTextDialog文本?

时间:2013-01-09 00:58:50

标签: c# showdialog

我有一个自定义控制台窗口,我用RichTextDialog编写,我想用它来执行文本io只需显示带有ShowDialog()的表单然后使用RichTextDialog的.Text属性或.AppendText()而不必调用Application编写程序代码后运行.Run()。所以,我想我试图绕过消息循环。这似乎是可能的,因为我可以在初始化期间从init方法设置对话框的文本。下面是代码供参考。当按原样运行时,仅写入“Sharp Console”。我当然可以为控制台编写我的程序(在更多io方法之后)然后完成。调用Application.Run()。但还有其他方法吗?

//SharpConsole.cs
namespace SharpConsole
{
    public class SConsole : Form
    {
        private RichTextBox tBox = null;

        public SConsole()
        {
            SetupComponents(); 
        }

        public void Write(string arg)
        {
            this.tBox.Text += arg;
        }

        private void SetupComponents()
        {
            tBox = new RichTextBox();
            this.SuspendLayout();

            this.tBox.Name = "tBox";
            this.tBox.Size = new Size(500, 400);
            this.ForeColor = Color.Black;
            this.tBox.TabIndex = 0;
            this.tBox.Text = "Sharp Console";//*****This works before Application.Run()********

            this.Size = new Size(500, 400);
            this.MaximizedBounds = new Rectangle(250, 100, 500, 400);
            this.MaximumSize = new Size(500, 400);
            this.Name = "SConsole";
            this.Text = "Sharp Console";

            this.Controls.Add(this.tBox);

            this.ResumeLayout(false);
        }    
    }
}


//SharpConsoleTest.cs
public class Program
{
    public static void Main()
    {
        SConsole console = new SConsole();

        ///I want to do this
        Console.ShowDialog();
        //And then write stuff
        console.Write("Hello");
        console.Write(" World!");

        //Without doing this last
        Application.Run(console);
    }
}

0 个答案:

没有答案