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?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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()
0
 
g_johnsonCommented:
frmSecond.showdialog   is like the old vb6   .show vbmodal
0
 
g_johnsonCommented:
oops, that's wrong -- i'll be right back with it
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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.

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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()
0
 
troyhalseyAuthor Commented:
I am getting this error when I try that:

Reference to a non-shared member requires an object reference.
0
 
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 :-)
0
 
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 :-)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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?
0
 
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.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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?
0
 
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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?...
0
 
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
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?
0
 
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.