Open Form

I am new to VB.Net...so forgive my ignorance.

How do I call up another form?  I have my parent form with a click handler.  When I click the button, I want to show another form within this parent.  How do I do this?  Thanks.

Troy
troyhalseyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

g_johnsonCommented:
frmSecond.showdialog   is like the old vb6   .show vbmodal
g_johnsonCommented:
oops, that's wrong -- i'll be right back with it
g_johnsonCommented:
you have to dim something as an instance of the form (i forgot)

e.g.,

dim f as new form2

f.show         or           f.showdialog


in .Net everything is an object; it doesn't exist until you instantiate it.

Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
In your click handler from your main form...   (assuming your main form is an Mdi form with IsMdiContainer set to True)

        Dim frm As New Form ' change "Form" to your Mdi child form name...
        frm.MdiParent = Me
        frm.Show()
troyhalseyAuthor Commented:
I am getting this error when I try that:

Reference to a non-shared member requires an object reference.
culshajaCommented:
StartPosition on each form allows you to set the default open location. You can set it to CenterParent and it will open centered above the calling form

James :-)
culshajaCommented:
Incase you need more info heres some detail on opening the form for the click handler

Dim f As New myForm
f.ShowDialog

That will open the new form modally and will open in the location set in the child forms StartPosition property.

james :-)
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You said:

    "I want to show another form within this parent."

The word "within" to me indicates an MDI Interface.  Are you working with MDI forms?
http://www.vb4all.pl/teoria/logos/kontrols/mdiform.gif

Or just regular forms and just want to open another form?
troyhalseyAuthor Commented:
Ok...I am getting close.  I got that to work...that you Idle Mind.....

Now, I thought I set my main form as the parent, but when I open the send form inside it....and then click on the man form menu, the child form dissappears.  How do I keep my main form active...while the child form is active as well?  In other words...the menu options on the main form need to be available to the child forms.  Thanks.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
By default Mdi child menus are "merged" with the Mdi parent menus....and child forms should not be disappearing.

Something else is going on here...can you please describe the bigger picture for us?  

And show us your code that you used to open the child form?
troyhalseyAuthor Commented:
I guess I should be asking....

How do I make my MainForm the parent...and subsequent forms child forms?

Sorry...learning from scratch.  

Troy
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Set the IsMdiContainer() property of your main form to True.

Then to make other forms Mdi Children you set their MdiParent() property to a reference to the Mdi Parent as I showed in my example above.

You do want your app to behave like the picture in the link I gave right?...
troyhalseyAuthor Commented:
Got it...you rock! Thanks Idle!

Okay my questions will continue...should I open a new question each time?

Next question is...

If frmChild...is already showing when I click the handler...how do I prevent duplicate windows from popping up? i.e.:

If frmChild visible, then exit sub... how do you write this in .Net?  I learned my basics in VBA...so it is an adjustment.

Troy
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Here is an example using Form3 as the Mdi Child...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim childFrm As Form
        For Each childFrm In Me.MdiChildren
            If TypeOf childFrm Is Form3 Then
                Exit Sub
            End If
        Next

        Dim frm As New Form3
        frm.MdiParent = Me
        frm.Show()
    End Sub
troyhalseyAuthor Commented:
Wait idle...just made a discovery.

The code you gave me create a New Child Form....I have created a form already that I want to show...called frmResources.  How do I get it to pop-up when I click the click handler?
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Something like...

        Dim childFrm As Form
        For Each childFrm In Me.MdiChildren
            If TypeOf childFrm Is frmResources Then
                If childFrm.WindowState = FormWindowState.Minimized Then
                    childFrm.WindowState = FormWindowState.Normal
                End If
                childFrm.Activate()
                Exit Sub
            End If
        Next

        Dim frm As New frmResources
        frm.MdiParent = Me
        frm.Show()

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
troyhalseyAuthor Commented:
That's what I am talking about!

Idle look for my questions, you will get lots of points from me.  haha.  Thanks all.

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