opening a child form from a dialog
-
Hi there I want to open a child form from a dialog form (.ShowDialog) and after the child form shows i want to close the dialog form. In the Dialog form there are 2 buttons: 1) btnclose which closes the dialog form 2) btnOpenChild which opens a child form and then closes itself (the dialog form) What should i do to get my desired result? I have included the codes to all the forms so that it may become easier to understand what i want to do. I am a total newbie, so plz do bare with me! Any help will be gr8! Thanks in Advance VisionTec ****************************** Form1 ( Main MDI Parent Form ) ******************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnChild;
private System.Windows.Forms.Button btnDialog;
private System.ComponentModel.Container components = null;public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.btnChild = new System.Windows.Forms.Button(); this.btnDialog = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnChild // this.btnChild.Location = new System.Drawing.Point(72, 112); this.btnChild.Name = "btnChild"; this.btnChild.TabIndex = 1; this.btnChild.Text = "open child"; this.btnChild.Click += new System.EventHandler(this.btnChild\_Click); // // btnDialog // this.btnDialog.Location = new System.Drawing.Point(208, 112); this.btnDialog.Name = "btnDialog"; this.btnDialog.TabIndex = 2; this.btnDialog.Text = "open dialog"; this.btnDialog.Click += new System.EventHandler(this.btnDialog\_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(408, 413); this.Controls.AddRange(new System.Windows.Forms.Control\[\] { this.btnDialog, this.btnChild}); this.IsMdiContainer = true; this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion \[STAThread\] st
-
Hi there I want to open a child form from a dialog form (.ShowDialog) and after the child form shows i want to close the dialog form. In the Dialog form there are 2 buttons: 1) btnclose which closes the dialog form 2) btnOpenChild which opens a child form and then closes itself (the dialog form) What should i do to get my desired result? I have included the codes to all the forms so that it may become easier to understand what i want to do. I am a total newbie, so plz do bare with me! Any help will be gr8! Thanks in Advance VisionTec ****************************** Form1 ( Main MDI Parent Form ) ******************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnChild;
private System.Windows.Forms.Button btnDialog;
private System.ComponentModel.Container components = null;public Form1() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code private void InitializeComponent() { this.btnChild = new System.Windows.Forms.Button(); this.btnDialog = new System.Windows.Forms.Button(); this.SuspendLayout(); // // btnChild // this.btnChild.Location = new System.Drawing.Point(72, 112); this.btnChild.Name = "btnChild"; this.btnChild.TabIndex = 1; this.btnChild.Text = "open child"; this.btnChild.Click += new System.EventHandler(this.btnChild\_Click); // // btnDialog // this.btnDialog.Location = new System.Drawing.Point(208, 112); this.btnDialog.Name = "btnDialog"; this.btnDialog.TabIndex = 2; this.btnDialog.Text = "open dialog"; this.btnDialog.Click += new System.EventHandler(this.btnDialog\_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(408, 413); this.Controls.AddRange(new System.Windows.Forms.Control\[\] { this.btnDialog, this.btnChild}); this.IsMdiContainer = true; this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion \[STAThread\] st
Well...I could not get your stuff to run (I think you forgot to paste the InitializeComponent() methods), so take this all with a grain of salt. You could just handle the closed event on your dialog form. Change / add this to form1
private void button2_Click(object sender, System.EventArgs e) { WindowsApplication1.frmDialog dialog = new WindowsApplication1.frmDialog(); dialog.Closed += new EventHandler (vShowChild); //NEW LINE dialog.ShowDialog(); } //NEW METHOD private void vShowChild(object sender, EventArgs e) { WindowsApplication1.frmChild child = new WindowsApplication1.frmChild(this); child.Show(); }
Then just close the dialog:private void button1_Click(object sender, System.EventArgs e) { // What should i write here to show the child form // and also to close this form after the child form shows?? this.Close(); //NEW LINE }
Hope this helps, Bill -
Well...I could not get your stuff to run (I think you forgot to paste the InitializeComponent() methods), so take this all with a grain of salt. You could just handle the closed event on your dialog form. Change / add this to form1
private void button2_Click(object sender, System.EventArgs e) { WindowsApplication1.frmDialog dialog = new WindowsApplication1.frmDialog(); dialog.Closed += new EventHandler (vShowChild); //NEW LINE dialog.ShowDialog(); } //NEW METHOD private void vShowChild(object sender, EventArgs e) { WindowsApplication1.frmChild child = new WindowsApplication1.frmChild(this); child.Show(); }
Then just close the dialog:private void button1_Click(object sender, System.EventArgs e) { // What should i write here to show the child form // and also to close this form after the child form shows?? this.Close(); //NEW LINE }
Hope this helps, BillHi there Thanks for the help but i actually want the child form to load when the user wants it to. so i have added another button to the Dialog form. i have updated the code on the discussions board and also uploaded the source code to my website: http://www.geocities.com/talhatec/downloads/WindowsApplication1.cab[^] the code is only 14K plz help me once again! VisionTec ( TEC )
-
Hi there Thanks for the help but i actually want the child form to load when the user wants it to. so i have added another button to the Dialog form. i have updated the code on the discussions board and also uploaded the source code to my website: http://www.geocities.com/talhatec/downloads/WindowsApplication1.cab[^] the code is only 14K plz help me once again! VisionTec ( TEC )
I think that someone else posted on this forum with exactly the same problem about a week ago... Look for a post titled : a parent-child problem, by Cem Louis try:http://www.codeproject.com/script/comments/forums.asp?msg=739514&forumid=1649#xx739514xx Cem's original source code is in the first message. I suggest a few changes in the second. This should get you on your way. Bill