Opening forms

I've been doing web forms and have not done any vb.net windows applications since
vb6 so I'm gonna have some basic questions . . like this:

a button on form1 is clicked,  . . I want to open form2 . .
then when form2 is done, I want to close it and go back to form1
LVL 16
MikeMCSDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
Hi MikeMCSD:
In VB.NET (as opposed to VB6) you have to create a form object

Dim f as New Form2
f.ShowDialog

Dabas
MikeMCSDAuthor Commented:
let me add one more thing:  I want to pass a variable to form2:
Dim prtName As String

Can I declare it on form1 so it will be available for form2?
MikeMCSDAuthor Commented:
thanks Dabas . . that was the fastest response ever!
Do I hide form1 or close it?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

MikeMCSDAuthor Commented:
why showDialog and not just show?
DabasCommented:
MikeMCSD:
ShowDialog is similar to vbModal in VB6
As to prtName, there are several ways of doing it.
Best way would be to add a public variable in Form2:

Public ParentForm as Form1

Then in Form1

Dim f as New Form2
f.ParentForm = Me
f.ShowDialog

In Form2 you can then use ParentForm.prtName

Dabas

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DabasCommented:
showDialog = VB6 show vbModal
show = VB6 show

You originally stated you wanted to make sure you get back to Form1

MikeMCSDAuthor Commented:
perfect . . thanks for your help
MikeMCSDAuthor Commented:
Visual studio is not liking the "ParentForm" name.  Should that be another name?

DabasCommented:
Ouch!
Did I choose a primitive?

Try changing it to MyParent
DabasCommented:
Strange. Just tried it out, but had no problem on my system.
MikeMCSDAuthor Commented:
in form2 it gives a blue line saying it conflicts with base class container control.
Can I use a module to declare public variables?
DabasCommented:
MikeMCSD:
> Can I use a module to declare public variables?
You can.

Dabas
DabasCommented:
MikeMCSD:
> it conflicts with base class container control
Maybe your app is MDI?
Just change the name to MyParent or anything else of your choosing.

Dabas
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.