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 C_Sharp_Form_Delegate_Events { public partial class Delegate_Events_Form : Form { private int formNo = 0; private System.Windows.Forms.Button btnYeniFormAc; //delege tanımlama public delegate void delegateDeneme(int formNumarasi); // olay tanımlama public event delegateDeneme eventDeneme; public Delegate_Events_Form() { InitializeComponent(); InitializeMyComponent(); } private void Form1_Load(object sender, EventArgs e) { this.eventDeneme += new delegateDeneme(Form1_eventDeneme); } public void yeniFormAc() { //yeni bir form oluştur MyForm form = new MyForm(); //her açılan form yeni bir id verelim //böylece hangi butonu tıklandığını tespit edebiliriz form.formNo = this.formNo++; //form da bir tane dinamik buton oluşturalım Button btn = new Button(); btn.Text = "Aktifleştir"; btn.Name = form.formNo.ToString(); btn.Size = new Size(100, 30); btn.Click += new EventHandler(btn_Click); //oluşturduğumuz bu butonu dinamik oluşturduğumyz forma ekleyelim form.Controls.Add(btn); //form için icon yükle form.Icon = C_Sharp_Form_Delegate_Events.Properties.Resources.Turkiye; //dinamik oluşan formu göster form.Show(); } void btn_Click(object sender, EventArgs e) { //oluşturulan butonun tıklama olayı yazdığımız olayı tetiklesini istiyoruz eventDeneme(int.Parse((sender as Button).Name)); } void Form1_eventDeneme(int formNumarasi) { MessageBox.Show("Acilan form no = " + formNumarasi); } private void btnYeniFormAc_Click(object sender, EventArgs e) { yeniFormAc(); } private void InitializeMyComponent() { this.btnYeniFormAc = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnYeniFormAc // this.btnYeniFormAc.Location = new System.Drawing.Point(72, 21); this.btnYeniFormAc.Name = "btnYeniFormAc"; this.btnYeniFormAc.Size = new System.Drawing.Size(131, 47); this.btnYeniFormAc.TabIndex = 0; this.btnYeniFormAc.Text = "Yeni Form Aç"; this.btnYeniFormAc.UseVisualStyleBackColor = true; this.btnYeniFormAc.Click += new System.EventHandler(this.btnYeniFormAc_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(273, 180); this.Controls.Add(this.btnYeniFormAc); this.Name = "Form1"; this.Text = "Ana Form"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } } public class MyForm : Form { public int formNo { get; set; } } }
Anasayfa
Button Sınıfı
C sharp uygulamalar
Click Event Örnekleri
Event - Delegate Örnekleri
Form Application Örnekleri
Form Sınıfı
C Sharp Uygulamalar Event - Delegate Tanımlama ve Tetikleme
28 Ocak 2014 Salı
Disqus Yorumları Yükle
Kaydol:
Kayıt Yorumları (Atom)
0 yorum