Multple Form

G

Guest

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.
 
T

Thomas P. Skinner [MVP]

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]
 
S

Sam Sungshik Kong

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top