Application with 3 Forms

  • Thread starter Thread starter Bruno Spirig
  • Start date Start date
B

Bruno Spirig

Hello

I have an application with 3 windows forms: Form1, Form2, Form3, where Form1
is the
startup form.
Form 1 call Form 2, Form 2 call Form 3, Form 3 should call Form 1.
With 'this.Close()' step-by-step work this, but it's not really clean and it
looks not fine.
How can i jump direct from Form3 to Form 1?
Or otherwise: How can i make a 'global' usable Form.

Thank you for help!

Best regards,
Bruno
 
With the 3 forms, what are you trying to accomplish overall? It might be
easier to make suggestions if we know the relationship(s) between these
forms.
 
Bruno,

If you make your forms singletons, you can improve performance and control
navigation. Example:

public class Foo : System.Windows.Forms.Form
{
private static Foo instance; // singleton

public static Foo GetInstance()
{
if ( instance == null )
{
instance = new Foo();
}
return instance;
}

So now you can write code like this:

Foo.GetInstance().Show();

-Darren
 
Hi Darren, Hi All

I have tryed your idea, but i get an error by close the Form3:
1. I place in each Form a GetInstance function
2.Button 'Jump to Form2' in Form 1: f2.GetInstance().ShowDialog();
3.Button 'Jump to Form3' in Form 2: f3.GetInstance().ShowDialog();
4. Button 'Jump to Form1' in Form 3: f2.GetInstance.Close();
-> ERROR Argument Execption
I tryed: first Close(); and then f2.GetInstance.Close();
I tryed: first f2.GetInstance.Close()and then Close();
I tryed a lot of other things but without a success.

What make i wrong?

Best regards,
Bruno
 
Don't worry about closing Form2. Your app has 3 forms. Navigate between
them with GetInstance().Show() and don't worry about closing or hiding
previous
forms.

-Darren
 
Hi Darren

My Forms must be 'locked', therefore i use ShowDialog();
With GetInstance().Show(), it works fine, but with
GetInstance().ShowDialog(), i get an error!
How can i make it with ShowDialog?

Best regards,
Bruno
 
Back
Top