代码实现窗体简单实例

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值