WinForms opening and closing forms sequentially

E

Ethan Strauss

I am (still) relatively new to Windows applications, most of my experience
has been Web based, and I am confused about what exactly happens when the
Main() method is called and how to manipulate forms opening & closing.

An example of this issue is as follows. I have a logon form open as the
first thing. The main functional form opens when a user has successfully
logged on. From the main form, a user should be able to logout which will
reshow the logon form and the state should be essentially identical to if
they have never logged on in the first place. What I find is that I can't
close any form in this string, or everything shuts down, so I have to hide
forms. But if I do that, then they still lurk in the background and do
strange things.

I have been thinking that I should make an orchestrator class with a method
something like this

public void ReplaceCurrentlyShownForm(Form toOpen, Form currentlyOpen)
{
currentlyOpen.Close();
currentlyOpen.Dispose();
toOpen.Show();
}
and have Main instantiate this class which then runs until the whole app is
closed down.
Would that make sense?

I have been looking for examples of code in which different windows forms
are show at different times in the program, but I have not yet found
anything. If you could point me to something, that would be helpful.
Thanks!
Ethan
 
E

Ethan Strauss

Thanks Peter.
That's helpful. I think I was making things way more complex than they
should be by using .ShowDialog() when that was not really what I wanted,
showing, hiding, and reshowing forms without making sure they were properly
refreshed and so forth. I think I can probably go back through and simply
everything by making sure that the initial form is not closed and making sure
I reset everything when a user ends up back at a form that had existed
before.
Ethan
 

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