- private System.Windows.Forms.Button btn_ok;
- private void InitializeComponent()
{
btn_ok.Location = new System.Drawing.Point(10, 80);
btn_ok.Name = "btn_ok";
btn_ok.Text = "手工按钮";
btn_ok.Size = new System.Drawing.Size(75, 23);
//eventhandler方法的参数就是事件名称,其实就是方法,
//你要手工编写,不然提示上下文找不到错误
btn_ok.Click += new System.EventHandler(this.btn_ok_click);
}
3,form1.cs关于事件btn_ok_click的代码// Form1
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.btn_ok);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
//
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.btn_ok);
this.Name = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
btn_ok.Location = new System.Drawing.Point(10, 80);
btn_ok.Name = "btn_ok";
btn_ok.Text = "手工按钮";
btn_ok.Size = new System.Drawing.Size(75, 23);
//eventhandler方法的参数就是事件名称,其实就是方法,
//你要手工编写,不然提示上下文找不到错误
btn_ok.Click += new System.EventHandler(this.btn_ok_click);
}
private void btn_ok_click(object sender, EventArgs e)
{
label1.Text = "手工编写事件处理代码,为了订阅事件所用";
}
{
label1.Text = "手工编写事件处理代码,为了订阅事件所用";
}