469,568 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

Multple Form

Hello,

I am new to C#. I have previously worked with VB6. My question is how to
work with two forms in an application. I have one form calling another form
when it is loaded. However, when I clock the first form, the second form
closes too. In the main method of the application it uses the
Application.Run(Form1) method to open the initial form. Therefore, when
Form1 closes, the entire application closes. I wanted to know if there is a
method that does not close the application until both forms have been closed
by the user.
Nov 16 '05 #1
2 1223
Try setting up an event handler in your main form for the Closing event. You
can then check if your other forms are closed. If not you can cancel the
event by setting the Cancel property in the CancelEventArgs to true.

Thomas P. Skinner [MVP]

"Kiet Quach" <Kiet Qu***@discussions.microsoft.com> wrote in message
news:43**********************************@microsof t.com...
Hello,

I am new to C#. I have previously worked with VB6. My question is how to
work with two forms in an application. I have one form calling another
form
when it is loaded. However, when I clock the first form, the second form
closes too. In the main method of the application it uses the
Application.Run(Form1) method to open the initial form. Therefore, when
Form1 closes, the entire application closes. I wanted to know if there is
a
method that does not close the application until both forms have been
closed
by the user.

Nov 16 '05 #2
You may change the main form during run-time.

static public ApplicationContext AC;
static void Main()
{
AC = new ApplicationContext();
Form1 f = new Form1();
AC.MainForm = f;
Application.Run(AC);
}
//Now you can change the main form to form2
AC.MainForm = form2;Sam"Kiet Quach" <Kiet Qu***@discussions.microsoft.com>
wrote in message news:43**********************************@microsof t.com...
Hello,

I am new to C#. I have previously worked with VB6. My question is how to
work with two forms in an application. I have one form calling another
form
when it is loaded. However, when I clock the first form, the second form
closes too. In the main method of the application it uses the
Application.Run(Form1) method to open the initial form. Therefore, when
Form1 closes, the entire application closes. I wanted to know if there is
a
method that does not close the application until both forms have been
closed
by the user.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John | last post: by
5 posts views Thread by Richard Cornford | last post: by
4 posts views Thread by Targa | last post: by
5 posts views Thread by Argirop | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.