using System;
using System.Windows.Forms;
using System.Drawing;
class MyForm
{
public static void Main()
{
Form fm = new Form();
fm.Text="我的每一个窗体";
fm.BackColor = Color.Red;
fm.ForeColor = Color.Blue;
Label lb = new Label();//标签控件
lb.Location = new Point(100, 50);
lb.Click+=new EventHandler(lb_Click);
lb.Text = "你好!";
fm.Controls.Add(lb);
Button bt = new Button();
bt.Click+=new EventHandler(bt_Click);
bt.Location = new Point(50, 100);
bt.Text = "我的Button";
bt.Size = new Size(50, 100);
fm.Controls.Add(bt);
//fm.Click += new EventHandler(fm_Click);
//fm.Paint += new PaintEventHandler(fm_Paint);
//fm.Load += new EventHandler(fm_Load);
// fm.GotFocus+=new EventHandler(fm_GotFocus);
fm.ShowDialog();
// Console.Read();
}
static void bt_Click(Object o, EventArgs e)
{
MessageBox.Show("Button响应");
}
static void lb_Click(Object o, EventArgs e)
{
MessageBox.Show("lable控件被点击了");
}
static void fm_GotFocus(Object o, EventArgs e)
{
MessageBox.Show("GotFocus事件响应");
}
static void fm_Load(Object o, EventArgs e)
{
MessageBox.Show("LOAD事件响应");
}
static void fm_Paint(Object o, EventArgs e)
{
MessageBox.Show("Paint 事件");
}
static void fm_Click(Object o, EventArgs e)
{
Console.WriteLine("你点击了窗体");
Console.WriteLine(o.ToString());
Console.WriteLine(e.GetType());
}
}
//using System;
using System.Windows.Forms;
using System.Drawing;
class MyForm : Form
{
private Button bt;
private Label lb;
public MyForm()
{
this.Text = "我的窗体";
this.BackColor = Color.Red;
this.Load+=new EventHandler(MyForm_Load);
this.bt = new Button();
bt.Text="我的BUTTON";
bt.Click+=new EventHandler(bt_Click);
bt.Location = new Point(100, 50);
this.Controls.Add(bt);
}
private static void bt_Click(Object o, EventArgs e)
{
MessageBox.Show("BUTTON事件响应");
}
private static void MyForm_Load(Object o, EventArgs e)
{
MessageBox.Show("窗体Load事件");
}
}//我自己新建的一个窗体类
class Program
{
public static void Main()
{
MyForm fm = new MyForm();
fm.ShowDialog();
}
}