jumping from one form to another
-
I wish to jump from running the main form Form1 to run my Form2. I want my Form2 to dispose Form1 and continue to run as the main form. I have excperienced som difficulty in doing this as when Form1 is disposed it will close Form2 even if i have set the reference in Form1 to acces Form2 to be null. I believe its because Form1 is running the main thread, is it possible for me to create a similar thread in Form2 to overtake the main thread.
-
I wish to jump from running the main form Form1 to run my Form2. I want my Form2 to dispose Form1 and continue to run as the main form. I have excperienced som difficulty in doing this as when Form1 is disposed it will close Form2 even if i have set the reference in Form1 to acces Form2 to be null. I believe its because Form1 is running the main thread, is it possible for me to create a similar thread in Form2 to overtake the main thread.
Form1
is what the message pump is using to keep the loop alive so that it translates and dispatches messages throughout your application (Windows Forms just encapsulates Windows messaging and common controls). Disposing your form (or even closing it) stops the message pump. If you're desiging a wizard-like interface, you should consider having a single form that maintains state between forms as well as navigation between them. And instead ofForm
derivatives, you could actually use any container control such as aUserControl
(easiest to design in VS.NET, if you like that sort of thing). There are several articles here on CodeProject that discuss this. If you want to create a new main window for your application, then you could try usingApplication.Run
on your instance ofForm2
then disposeForm1
. I'm not sure how this would affect your application, however, since a new STA thread would be created for the new main window. Give it a try, though.Microsoft MVP, Visual C# My Articles