Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Open Form

Posted on 2006-04-05
17
Medium Priority
?
518 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
0
Comment
Question by:troyhalsey
  • 6
  • 6
  • 3
  • +1
17 Comments
 
LVL 4

Expert Comment

by:g_johnson
ID: 16382164
frmSecond.showdialog   is like the old vb6   .show vbmodal
0
 
LVL 4

Expert Comment

by:g_johnson
ID: 16382181
oops, that's wrong -- i'll be right back with it
0
 
LVL 4

Expert Comment

by:g_johnson
ID: 16382196
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16382209
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
 

Author Comment

by:troyhalsey
ID: 16382216
I am getting this error when I try that:

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

Expert Comment

by:culshaja
ID: 16382228
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
 
LVL 7

Expert Comment

by:culshaja
ID: 16382252
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16382266
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
 

Author Comment

by:troyhalsey
ID: 16382297
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16382437
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
 

Author Comment

by:troyhalsey
ID: 16382504
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16382756
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
 

Author Comment

by:troyhalsey
ID: 16382878
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16382929
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
 

Author Comment

by:troyhalsey
ID: 16382965
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
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16383017
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
 

Author Comment

by:troyhalsey
ID: 16383036
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question