C#動(dòng)態(tài)創(chuàng)建button按鈕的方法實(shí)例詳解
C#編程中經(jīng)常需要?jiǎng)討B(tài)創(chuàng)建,本文主要介紹C#動(dòng)態(tài)創(chuàng)建button按鈕的方法,涉及C#按鈕屬性動(dòng)態(tài)設(shè)置的相關(guān)技巧,以供借鑒參考。具體實(shí)現(xiàn)方法如下:
例子:
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; using System.Reflection; namespace App {  public partial class Form1 : Form  {   public Form1()   {    InitializeComponent();    System.Windows.Forms.Button button = new Button();    button.Text = "按鈕";    button.Size = new Size(100, 30);    button.Location = new Point(0, 0);    button.Click += delegate    {     ButtonClick();    };    this.Controls.Add(button);   }   void ButtonClick()   {    MessageBox.Show("點(diǎn)擊了click事件");   }  } } //注意:主要是看事件感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選