Application with 3 Forms

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
 
T

Tim Wilson

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

Darren Shaffer

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
 
B

Bruno Spirig

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
 
D

Darren Shaffer

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
 
B

Bruno Spirig

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
 

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