Click here to Skip to main content
15,914,500 members
Home / Discussions / C#
   

C#

 
AnswerRe: need sql query? Pin
John Kuhn18-Feb-04 19:34
John Kuhn18-Feb-04 19:34 
QuestionHow to Communicate with SerialPort Use C# Programming? Pin
skywen18-Feb-04 16:16
skywen18-Feb-04 16:16 
AnswerRe: How to Communicate with SerialPort Use C# Programming? Pin
Corinna John18-Feb-04 20:53
Corinna John18-Feb-04 20:53 
GeneralRe: How to Communicate with SerialPort Use C# Programming? Pin
skywen18-Feb-04 21:09
skywen18-Feb-04 21:09 
GeneralRe: How to Communicate with SerialPort Use C# Programming? Pin
Corinna John18-Feb-04 21:24
Corinna John18-Feb-04 21:24 
GeneralRe: How to Communicate with SerialPort Use C# Programming? Pin
eggie519-Feb-04 1:48
eggie519-Feb-04 1:48 
GeneralRe: How to Communicate with SerialPort Use C# Programming? Pin
Corinna John19-Feb-04 2:41
Corinna John19-Feb-04 2:41 
Generalopening a child form from a dialog Pin
visiontec18-Feb-04 15:26
visiontec18-Feb-04 15:26 
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]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void btnChild_Click(object sender, System.EventArgs e)
		{
			WindowsApplication1.frmChild child = new WindowsApplication1.frmChild(this);
			child.Show();
		}		

		private void btnDialog_Click(object sender, System.EventArgs e)
		{
			WindowsApplication1.frmDialog dialog = new WindowsApplication1.frmDialog();
			dialog.ShowDialog();
		}
	}
}

*************************
frmDialog ( Dialog Form )
*************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsApplication1
{
	public class frmDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnOpenChild;
		private System.ComponentModel.Container components = null;

		public frmDialog()
		{
			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.btnClose = new System.Windows.Forms.Button();
			this.btnOpenChild = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnClose
			// 
			this.btnClose.Location = new System.Drawing.Point(32, 96);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 0;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnOpenChild
			// 
			this.btnOpenChild.Location = new System.Drawing.Point(152, 96);
			this.btnOpenChild.Name = "btnOpenChild";
			this.btnOpenChild.TabIndex = 1;
			this.btnOpenChild.Text = "open child";
			this.btnOpenChild.Click += new System.EventHandler(this.btnOpenChild_Click);
			// 
			// frmDialog
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnOpenChild,
																		  this.btnClose});
			this.Name = "frmDialog";
			this.Text = "frmDialog";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close(); // close this form
		}

		private void btnOpenChild_Click(object sender, System.EventArgs e)
		{
			//What should i write here to open the child form?
			//And then close this form?
		}
	}
}

***********************
frmChild ( child form )
***********************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowsApplication1
{
	
	public class frmChild : System.Windows.Forms.Form
	{
		
		private System.ComponentModel.Container components = null;

		public frmChild(WindowsApplication1.Form1 parent)
		{
			InitializeComponent();
			this.MdiParent = parent;
		}

		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.components = new System.ComponentModel.Container();
			this.Size = new System.Drawing.Size(300,300);
			this.Text = "frmChild";
		}
		#endregion
	}
}
}

GeneralRe: opening a child form from a dialog Pin
Bill Dean19-Feb-04 1:40
Bill Dean19-Feb-04 1:40 
GeneralRe: opening a child form from a dialog Pin
visiontec19-Feb-04 11:45
visiontec19-Feb-04 11:45 
GeneralRe: opening a child form from a dialog Pin
Bill Dean19-Feb-04 17:46
Bill Dean19-Feb-04 17:46 
GeneralRecord sound from sound card Pin
suki_yip18-Feb-04 15:21
suki_yip18-Feb-04 15:21 
GeneralRe: Record sound from sound card Pin
Heath Stewart19-Feb-04 4:43
protectorHeath Stewart19-Feb-04 4:43 
GeneralEos: aspect-oriented extension for C# Pin
Hridesh Rajan18-Feb-04 15:08
Hridesh Rajan18-Feb-04 15:08 
GeneralAutomate Legacy 3270 Applications Pin
John Kuhn18-Feb-04 14:36
John Kuhn18-Feb-04 14:36 
Generalpostback problem Pin
pardu18-Feb-04 14:34
pardu18-Feb-04 14:34 
GeneralRe: postback problem Pin
Nick Parker18-Feb-04 18:17
protectorNick Parker18-Feb-04 18:17 
General"Minimize to tray" button in title bar Pin
josefg18-Feb-04 12:30
josefg18-Feb-04 12:30 
GeneralRe: "Minimize to tray" button in title bar Pin
Heath Stewart19-Feb-04 4:38
protectorHeath Stewart19-Feb-04 4:38 
GeneralRe: "Minimize to tray" button in title bar Pin
John Fisher19-Feb-04 5:16
John Fisher19-Feb-04 5:16 
GeneralControlling file permissions Pin
james-cxx18-Feb-04 12:05
james-cxx18-Feb-04 12:05 
GeneralRe: Controlling file permissions Pin
Russell Morris18-Feb-04 12:27
Russell Morris18-Feb-04 12:27 
GeneralRe: Controlling file permissions Pin
james-cxx19-Feb-04 6:51
james-cxx19-Feb-04 6:51 
GeneralWriting to MXL File Pin
Mr_Mike18-Feb-04 11:27
Mr_Mike18-Feb-04 11:27 
GeneralRe: Writing to MXL File Pin
Kentamanos18-Feb-04 12:50
Kentamanos18-Feb-04 12:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.