tom
tom

Reputation: 5001

References to open forms

i am creating a programme where the user enters some data in to the opening form. based on that another window will open. In total i have 4 guis which work on a cyclical basis. You can get from one form to any of the others after a series of different clicks.

Without having to reload some of the forms from scratch (as some have many queries that need to be run) and without having to form1,form2,form3.hide(), form4.show()

how can i do it "properly" :D

Thanks

Upvotes: 0

Views: 94

Answers (3)

user492238
user492238

Reputation: 4084

No really. Why not:

private static Form[] _forms = new Form[] { form1, form2, form3, form4 }; 
public static void ShowForm(Form form) {
    foreach (Form f in _forms)  {
        if (f == form) 
            f.Show(); 
        else 
            f.Hide(); 
    }
}

Upvotes: 0

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236268

You can use UserControls on one form, instead of working with many forms. Active control could be easily switched by calling userControl1.BringToFront() method.

Upvotes: 1

Davide Piras
Davide Piras

Reputation: 44605

If you always show them in the same order, you can use the Wizard approach, it's also useful if in the future you will add new forms in the middle or in the "edges", usually a wizard application holds somewhere a structure with all relevant data shared from all forms. Hope this helps.

Upvotes: 0

Related Questions