Question Loading instance of a form from another

bhasky12345

New member
Joined
Jan 29, 2013
Messages
2
Programming Experience
Beginner
Hi All,

I am creating one application with 2 forms. Step1 is the first form and Step2 is the second one. I can load the second form from the first one. How do I create an instance of the first form and call it from the second form? I dont want to load the first form afresh, instead, I want to load the last instance of the first form (from the second form, may be using a Back button) where user would already have filled in some data and navigated to the second form.
I can create an instance of the first form as
DIM F1 As Step1

But I don't seem to have been able to use
F1.show()
from the second form.
Hope my requirement is clear to you.
I am sorry, I am quite new to VB.NET. Please help.

Thanks in adv.
 
Last edited by a moderator:
You don't need any code at all in the second form. The first form can do it all. If you want to use the same instance of the first form then you can't close it, because that will destroy it. You must hide it instead. In the first form, just do this:
VB.NET:
Using f2 As New Form2
    Hide()
    f2.ShowDialog()
    Show()
End Using
Form1 will hide itself and show Form2 as a dialogue, then show itself again when Form2 closes. In fact, you may not even need to bother hiding and showing Form1 because, if Form2 is displayed as a modal dialogue, it will prevent access to Form1 anyway.
 
Thanks a lot. It serves my purpose if I use only 2 forms. What if I have three forms? Navigation is as follows:
Step1 -> Step2 -> Step3
From Step3, I should be able to go to Step1 as well as Step2. Basically, I do not want to close the forms as I want to reuse the details. Can you suggest me the approach?
Thanks again.

-Bhaskar
 
No Bhaskar you are misunderstanding, by using the statement new Form2 you are declaring a new instance of that very form.

Why not just use
VB.NET:
form1.show
Or if you must
VB.NET:
dim f1 as new form1
f1.show
 
Back
Top