We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Open Form

troyhalsey
troyhalsey asked
on
Medium Priority
540 Views
Last Modified: 2007-11-27
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
Comment
Watch Question

frmSecond.showdialog   is like the old vb6   .show vbmodal
oops, that's wrong -- i'll be right back with it
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.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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()

Author

Commented:
I am getting this error when I try that:

Reference to a non-shared member requires an object reference.

Commented:
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 :-)

Commented:
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, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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?

Author

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, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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?

Author

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, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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?...

Author

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, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
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

Author

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?
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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()

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.