Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Child creation question?

Status
Not open for further replies.

other3

Programmer
Jul 30, 2002
92
US
In VB.NET I have the following code.
"
If Not m_bCDSform Then
m_cdsForm = New cdsForm

m_cdsForm.MdiParent = Me

m_cdsForm.Show()
Else
m_cdsForm.BringToFront()
End If

Public Sub setCDsForm(ByVal bOpen As Boolean)
m_bCDSform = bOpen
End Sub
"

When the m_cdsForm loads it does the following.

"
Dim MyMDIParent = Me.MdiParent.FindForm

MyMDIParent.setCDsForm(True)
"

Is there a way to accomplish the same sort of thing in VB 6.0? Any help would be greatly appreciated. Thanks in advance.

Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
Set the MDIChild property to True on the form you want to be a child.

To call from parent:

Dim F as Form1
Set F = Form1
F.Show

I hope this helps.

Ron

Ron Repp
 
Ron:

Thank you for your response. I have no trouble with bring up a MDIChild form. The problem is I do not know enough object orientedness of VB 6.0 to access the parent form from the child after it is up and showing to be able to make it the active form.


Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
NameOfForm.tbToolbar.Buttons("Bold").Value = tbrPressed

This line of code would access the parent form's toolbar button with the Tag "Bold" and press it.

In VB6, the OOP is much looser. You do not have to declare forms, for one thing.

However, I don't want to spout because there are a zillion programmers who read these threads and any one of them knows better ways of doing things.

I hope this helps.

Ron

Ron Repp
 
For a better understanding, in VB6, start a New Project by going File>New. In the dialog box, choose VB Application Wizard and double click. The third screen of the wizard asks what type of interface. Choose MDI and then click Finish.

This leaves you with two forms, the MDI (Parent) and frmDocument (child). Go behind frmDocument to see how the code is handled where it pertains to objects that are "owned" by the parent.

I hope this helps,

Ron

Ron Repp
 
Ron

Thanks much for all your help. What I'm trying to replicate in VB 6.0 is kinda not a true use of MDI in the classic sense.

What I did in VB.NET is create a MDI parent that essentally can bring up a possable three MDI children that are essentally stand alone dialog boxes.

I have the whole MDI thing going in VB 6.0. The problem is that when I go to bring up another form/dialog of the same type from the menu, I get another form instead of the already active form coming to the front so that the Close option on the File menu will close the first form/dialog.

It's a, the VB.NET, goofy application that is just making use of the MDI form.

If you look at the code at the top, first part in quotes is in the MDI parent and is executed when I choose from the menu to bring up that form. The second part in quotes is in the form load of the child and calls a function in the parent that sets a boolean so that by clicking on the parent menu does not create a second from but brings it to the front of three possable forms. What I need is to know how to do the same type of thing in VB 6.0.

Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
First, VB6 is much more restrictive with MDI parent/child relationships than .Net is. You can only have one MDI parent in the project, so there's no need (also no way) to specifically relate MDI parents and children. You have one MDI form, and you then can have any number of different types of MDI Child forms. When you show the MDI Parent, you automatically have one instance of the first MDI Child form in your project explorer. If you want to add an instance of another form or forms, you do so in the MDI Parent's load event, as in Ron's first post, with a small correction:
Code:
Dim F as Form2
Set F = [COLOR=red]New[/color] Form2
F.Show
You can then set F to New Form3 and show it, and so on.

Now then. I believe you're saying that you want an MDI parent form to expose 3 different MDI children, when the MDI parent form is loaded from another form in your project. You then want to have one of these children be the active form. If this is what you in fact want to do, this is very trivial in VB6, more so than in .Net.

Try adding a picture box to your MDI Parent form. On this picture box, add a command button. (Yes, you can use a menu, but I thought you might like to know that you can do this too!) In the click event, put
Code:
Forms(1).SetFocus
This would focus on the first child form loaded and make it the active form. If you used forms(2), it would make the second form loaded the active form, and so on. (Interestingly, as I just found out, if you use the form name instead of the form number with SetFocus it will create a new instance of the form, if you created the form manually using the technique in the first code block.)

HTH,

Bob
 
Thank you all for all of your suggestions, I've been sitting here working on the thing waiting in the cold for the furnace guy to so up. It's 11:00pm. Anyway, I've got it now so that only one instance of each child form will come up when selected from a menu.

I will try the last suggestion in order to bring the form I want to the fore ground and therefore make it the active form so that Close will close it.

Another thing I just noticed, if there is nothing to Close,
Unload Me.ActiveForm blows up.

Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
<Another thing I just noticed, if there is nothing to Close,
Unload Me.ActiveForm blows up.

Why yes, since there isn't an active form. This gets into our related thread thread222-1169407 a bit.

You can figure out whether you have an activeform by evaluating Forms.Count. If Forms.Count is equal to the number of forms you have open when there are no mdi children open, then you can avoid your unload logic.

HTH

Bob
 
Bob, and all who have responded so generously to my original question. I thank you so much. Thanks for your latest tip. I had each form seting a boolean in the parent and then disbling the Close on the menu when a I would set it to false when I closed a child form.

I will read back through all the input on this thread and also check out the one that you referenced. I guess The Grateful Dead, as opposed to The Dead, which is what they toured as last and have adopted as their name and BTVS haven't taught me very much. Just kidding.

My next endevor, spelling?, is to figure out how to fill in data grids. .NET makes all of that soooooo simple.


Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
<I had each form seting a boolean in the parent and then disbling the Close on the menu when a I would set it to false when I closed a child form.

I think evaluating the Forms collection is simpler.

<My next endevor, spelling?, is to figure out how to fill in data grids.

Check the FlexGrid and Hierarchical FlexGrid controls. DO NOT use the Data Control. Use ADO objects.

It's "endeavor" (or "endeavour" if you're British), by the way. :)

Bob
 
Think this horse is beat. Take and thanks much.

Everything I know I learned from The Grateful Dead and Buffy The Vampire Slayer
Charlie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top