using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("已经单击了窗体!");
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("已经单击了窗体!");
}
}
}
//需要为当前对象添加单击事件才可以响应事件方法
this.Click += new System.EventHandler(this.Form1_Click);
this.Click += new System.EventHandler(this.Form1_Click);
这个是 事件和委托挂钩。
//为button1添加单击
this.button1.Click += new System.EventHandler(this.Form1_Click);
this.Click += new System.EventHandler(this.Form1_Click);
因为我之前都只是在Form1.cs编写代码的呀???