c# event在form中手工編寫一個按鈕button

wisdomone1發表於2012-03-08
//InitializeComponent為設計生成的方法程式碼


  1. private System.Windows.Forms.Button btn_ok;
  2. private void InitializeComponent()
        {

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

           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的程式碼
 private void btn_ok_click(object sender, EventArgs e)
        {
            label1.Text = "手工編寫事件處理程式碼,為了訂閱事件所用";
        }


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-718079/,如需轉載,請註明出處,否則將追究法律責任。

相關文章