您的位置:首页 > 其它

手写一个简单的WinForm程序(2)

2008-10-09 16:36 288 查看
经过高人指教之后的代码:

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();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: