filleActive = (Maman) this.ActiveMdiChild;
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.IO; namespace testHeritage { public class formParent : System.Windows.Forms.Form { private System.Windows.Forms.Button btnSave; formFille1 myFormFille1; formFille2 myFormFille2; public formParent() { InitializeComponent(); this.IsMdiContainer = true; //fille1 myFormFille1 = new formFille1(); myFormFille1.MdiParent = this; myFormFille1.Show(); //fille2 myFormFille2 = new formFille2(); myFormFille2.MdiParent = this; } private void InitializeComponent() { this.btnSave = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnSave // this.btnSave.Location = new System.Drawing.Point(272, 8); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(64, 24); this.btnSave.TabIndex = 0; this.btnSave.Text = "Save"; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // // formParent // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(608, 485); this.Controls.AddRange(new System.Windows.Forms.Control[] this.btnSave}); this.IsMdiContainer = true; this.Text = "formParent"; this.ResumeLayout(false); } [STAThread] static void Main() { Application.Run(new formParent()); } private void btnSave_Click(object sender, System.EventArgs e) { Maman filleActive; filleActive = (Maman) this.ActiveMdiChild; filleActive.saveFille(); } } public class formFille1 : System.Windows.Forms.Form,Maman { public formFille1() { this.ClientSize = new System.Drawing.Size(100, 100); this.Text = "formFille1"; } public void saveFille() { Console.WriteLine ("save fille 1"); } } public class formFille2 : System.Windows.Forms.Form,Maman { public formFille2() { this.ClientSize = new System.Drawing.Size(100, 100); this.Text = "formFille2"; } public void saveFille() { Console.WriteLine ("save fille 2"); } } interface Maman { void saveFille(); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question