private void addButton(String name, String text, int x, int y, int width, int height, int tabIndex = 0) //Button oluşturma fonksiyonumuz
{
this.SuspendLayout(); //Görüntüyü düzenlemek için durduruyorsun
Button newButton = new Button();
newButton.Location = new System.Drawing.Point(x, y); //Lokasyonu
newButton.Name = name; //Variable Adı
newButton.Size = new System.Drawing.Size(width, height); //Büyüklüğü
newButton.TabIndex = tabIndex; //Tab Index
newButton.Text = text; //Görünen ismi
newButton.UseVisualStyleBackColor = true;
newButton.Click += button_Click; //Aşağıdaki tıklama eventine kaydetme
this.Controls.Add(newButton); //Yeni butonu form'a ekliyoruz
this.ResumeLayout(false); //Görüntüyü devam ettiriyorsun
}
private void button_Click(object sender, EventArgs e) //Buttonların genel tıklanma aktivitesi
{
Button button = (Button) sender; //Casting
if(button.Name == "test0") //Hangi buton olduğunu kontrol etme
MessageBox.Show("Tıklandı.");
else
MessageBox.Show("2. Buton");
}