Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. opening a child form from a dialog

opening a child form from a dialog

Scheduled Pinned Locked Moved C#
graphicsdockerhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    visiontec
    wrote on last edited by
    #1

    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
    
    B 1 Reply Last reply
    0
    • V visiontec

      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
      
      B Offline
      B Offline
      Bill Dean
      wrote on last edited by
      #2

      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 form1private 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

      V 1 Reply Last reply
      0
      • B Bill Dean

        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 form1private 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

        V Offline
        V Offline
        visiontec
        wrote on last edited by
        #3

        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 )

        B 1 Reply Last reply
        0
        • V visiontec

          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 )

          B Offline
          B Offline
          Bill Dean
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups