手写一个简单的WinForm程序(2)
經過高人指教之后的代碼:
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();
??????? }
??? }
}
轉載于:https://www.cnblogs.com/min10/archive/2008/10/09/1307367.html
總結
以上是生活随笔為你收集整理的手写一个简单的WinForm程序(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 长安押宝阿维塔电动汽车:宣布增资11.6
- 下一篇: 建行分期通审批容易吗?综合评分低会被拒