Question Mdi

gate7cy

Well-known member
Joined
May 11, 2009
Messages
119
Programming Experience
3-5
have been developing an application for quite some time now. I have decided to create an mdi parent form to hold all the windows I have done so far. Is there an easy way to implement the mdi parent/ child associations??? Any suggestions? Thanks for the replies.
 
In the main form's properties you can set IsMdiContainer to True. Then when this form calls new forms use this:

VB.NET:
Expand Collapse Copy
Dim frm As New Form2
frm.MdiParent = Me
frm.Show
 
forms call each other and also the main form call them. how do I do the forms being calling each other having mdiparent the main form? Thanks for the reply
 
So you are saying you have an MdiChild that is calling other forms and that you want these forms to be child forms of the main form(MdiParent), right? Somewhat confusing concept.
 
You can still call the forms and assign them to the MdiParent form. Using the keyword "Me" is an easy way of skipping writing the forms name. You can replace "Me" with the name of your MdiParent form from any form

From any form, call your new form and assign it to the MdiParent form

VB.NET:
Expand Collapse Copy
    Dim frm As New Form3
    frm.MdiParent = frmMdi
    frm.Show
 
that is basically what I wanted to know. The issue is that how do I call mdichild forms from an mdichild form? And how will the mdichild form know in which form to send/receive the correct data? Thanks for the reply
 
As said above in any form, even a child form you can call another child form and instead of using the Me keyword replace it with the name of your parent form.

As to passing data between forms; that also remains the same. You can pass data directly through properties, parameters of a sub or function being called or store it in global scope variables in a module. If you want a more specific reference/example then you will have to provide further details on exactly what/how you are trying to pass data.
 
When you show the form give it an owner:
VB.NET:
Expand Collapse Copy
Dim frm As New Form2
frm.Show(frmMdi)
Then in the child call it:
VB.NET:
Expand Collapse Copy
DirectCast(Me.Owner, frmMdi).<method>
JuggaloBrotha posted a similar solution, I modified it for your purpose.
 
thanks for the replies guys. newguy I have tried your suggestion, what look like the answer but I get an errror :

Invalid Cast exception was unhandled. Unable to cast object of type app.main to type app.int
app.main being my mdi parent and app.int is form1. What is not written in the error is form2 where the casting code was written and the exception was raised. Any thoughts on this? Is says something about conversion but I am passing from a textbox having string values to a textbox saving a string value. thanks for the replies
 
Gate7cy it is really very easy to call & show child forms from any form that you want including other child forms. I'm not sure if your misunderstanding my previous post or not but I'll attach an example to show this. If you still need help after taking a look at the example just let me know.
 

Attachments

thanks for the reply tom. but you missed out on the following forms as now I am trying to find out how to send data between child forms. I have form1 and form2 and both are mdichildren. They do not recognize each other even though form2 is called from form1. I want to send data from form2 to form1. Any suggestions??
 
There are many ways of passing data between forms. You can store values in global variables that can be seen by all forms, you can set up public properties to pass data, you can pass values thru the parameters of a start up sub or function or even adding a parameter to the sub New.

Here is another example
 

Attachments

Back
Top