A child-parent problem...
-
Hi to all, I have 3 dialogs which are Parent, Dialog and Child. When I press My Parent dialog's menu I come across with my dialog box. Everything ok for now. But when I press the button on dialog I want my child dialog inside the parent dlg box. I think I made something wrong the code runs without any errors but doesn't make what I want??? Might be a logic failure in somewhere. This trashed all my day (I brainstrom and checked lots of articles about forms...) But couldn't get a result. So any help would be greatly appreciated. I am posting all my 3 file(Sorry for the pollution) Thank you, Cem Louis ///////////// //Parent.cs// ///////////// using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Test1 { /// /// Summary description for Parent. /// public class Parent : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Parent() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "Show Dialog"; // // menuItem2 // this.m
-
Hi to all, I have 3 dialogs which are Parent, Dialog and Child. When I press My Parent dialog's menu I come across with my dialog box. Everything ok for now. But when I press the button on dialog I want my child dialog inside the parent dlg box. I think I made something wrong the code runs without any errors but doesn't make what I want??? Might be a logic failure in somewhere. This trashed all my day (I brainstrom and checked lots of articles about forms...) But couldn't get a result. So any help would be greatly appreciated. I am posting all my 3 file(Sorry for the pollution) Thank you, Cem Louis ///////////// //Parent.cs// ///////////// using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace Test1 { /// /// Summary description for Parent. /// public class Parent : System.Windows.Forms.Form { private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Parent() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "Show Dialog"; // // menuItem2 // this.m
Hi, I think I know the problem. When you launch the program, you create an instance of the class "parent". But since you do not pass the object to Dialog, you can't refer to it there. Here's what I did that seemed to produce the effect you want: 1) modify Dialog.cs so that you can store the parent object somewhere. Add this on line 20 or so
public class Dialog : System.Windows.Forms.Form { private Form MainForm; //bill dean says add this! private System.Windows.Forms.Button button1;
2) Modify the constructor for for Dialog so you can pass it a the parent.public Dialog(Form frmMain) //bill dean says change here! { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.MainForm = frmMain; //bill dean says change here! }
3) Pass the parent object when you instantiate the form...in Parent.csprivate void menuItem2_Click(object sender, System.EventArgs e) { Test1.Dialog Dialog = new Test1.Dialog(this); //bill dean says add this. Dialog.Show(); }
4) Then (finally!) set the mdiparent for the Childprivate void button1_Click(object sender, System.EventArgs e) { Test1.Child chform = new Test1.Child(); chform.MdiParent = this.MainForm; chform.Show (); }
Hope this helps! I can send you the source code if this post doesn't get the message across... ;) Bill -
Hi, I think I know the problem. When you launch the program, you create an instance of the class "parent". But since you do not pass the object to Dialog, you can't refer to it there. Here's what I did that seemed to produce the effect you want: 1) modify Dialog.cs so that you can store the parent object somewhere. Add this on line 20 or so
public class Dialog : System.Windows.Forms.Form { private Form MainForm; //bill dean says add this! private System.Windows.Forms.Button button1;
2) Modify the constructor for for Dialog so you can pass it a the parent.public Dialog(Form frmMain) //bill dean says change here! { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.MainForm = frmMain; //bill dean says change here! }
3) Pass the parent object when you instantiate the form...in Parent.csprivate void menuItem2_Click(object sender, System.EventArgs e) { Test1.Dialog Dialog = new Test1.Dialog(this); //bill dean says add this. Dialog.Show(); }
4) Then (finally!) set the mdiparent for the Childprivate void button1_Click(object sender, System.EventArgs e) { Test1.Child chform = new Test1.Child(); chform.MdiParent = this.MainForm; chform.Show (); }
Hope this helps! I can send you the source code if this post doesn't get the message across... ;) Bill//bill dean says kids, stay in school
;)
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins -
Hi, I think I know the problem. When you launch the program, you create an instance of the class "parent". But since you do not pass the object to Dialog, you can't refer to it there. Here's what I did that seemed to produce the effect you want: 1) modify Dialog.cs so that you can store the parent object somewhere. Add this on line 20 or so
public class Dialog : System.Windows.Forms.Form { private Form MainForm; //bill dean says add this! private System.Windows.Forms.Button button1;
2) Modify the constructor for for Dialog so you can pass it a the parent.public Dialog(Form frmMain) //bill dean says change here! { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.MainForm = frmMain; //bill dean says change here! }
3) Pass the parent object when you instantiate the form...in Parent.csprivate void menuItem2_Click(object sender, System.EventArgs e) { Test1.Dialog Dialog = new Test1.Dialog(this); //bill dean says add this. Dialog.Show(); }
4) Then (finally!) set the mdiparent for the Childprivate void button1_Click(object sender, System.EventArgs e) { Test1.Child chform = new Test1.Child(); chform.MdiParent = this.MainForm; chform.Show (); }
Hope this helps! I can send you the source code if this post doesn't get the message across... ;) Bill