手写一个简单的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();
}
}
}
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();
}
}
}
相关文章推荐
- 手写一个简单的WinForm程序
- 手写一个简单的Servlet程序
- 用C# WinForm写的一个简单的计算器程序(可以输入复杂的表达式),欢迎大家指出Bug
- 黑马程序员--学习笔记--一个WinForm简单加法练习程序
- 黑马之前,一个简单的winform程序
- 一个WinForm程序配置信息的简单模型和维护工具——设计说明
- 一个WinForm程序配置信息的简单模型和维护工具——使用说明
- 一个简单的执行程序的GNU automake自动生成Makefile的方法及案例
- 脱离IDE的一个简单C#程序(上)
- API入门系列之四 -一个相当简单的SDK程序
- VC-Logger 是一个简单易用的 C++ 程序通用日志组件
- Rhyme/ 手写服务器 实现一个基于xml解析的简单的Tomcat服务器
- 一个简单FTP程序的主要源代码
- 一个简单的目录复制程序
- java中数组的运用制作一个简单的购物程序
- 创建一个简单的WCF程序
- 一个简单、漂亮、功能强大的Android日志程序:logger
- 创建一个简单的WCF程序(二)
- 一个简单的数据收集程序
- 一个简单的购物车程序