min10

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

经过高人指教之后的代码:

using System;
using System.Windows.Forms;
using System.Drawing;

namespace MyApplication
{
    public partial class Form1 : Form
    {
        private delegate void ShowText();
        TextBox textBox1 = new TextBox();
        Button button1 = new Button();

        public Form1()
        {
            textBox1.Text = "Hello world!";
            textBox1.Location = new Point((Width - textBox1.Width) / 3, (Height - textBox1.Height) / 3);
            textBox1.Parent = this;
            button1.Text = "button1";
            button1.Location = new Point(textBox1.Left + textBox1.Width + 8, textBox1.Top);
            button1.Click += new EventHandler(button1_Click);
            button1.Parent = this;
            this.ShowDialog();
        }

        void button1_Click(Object sender, EventArgs e)
        {
            Invoke(new ShowText(DoShowText));
        }

        void DoShowText()
        {
            MessageBox.Show(textBox1.Text);
        }

        static void Main()
        {
            Form1 form1 = new Form1();
        }
    }
}

posted on 2008-10-09 16:36  min10  阅读(308)  评论(0编辑  收藏  举报