How to keep a Child Form of a MDI Child contained

G

Guest

I have an issue with a Child Form of a MDI Child staying contained within the
Master Form.

My first Form is called mdiMaster, which opens the mainMenu form with the
following code:
Dim MainMenu As New MainMenu
MainMenu.MdiParent = Me
MainMenu.Show()

Then a button click event of the mainMenu opens an application form with the
following code:
Dim applicantion As New applicantion
applicantion.MdiParent = Me.MdiParent
applicantion.Show()

The problem occurs when the application form tries to open another form, I
have the following code:
Dim searchForms As New SearchForms
searchForms.MdiParent = Me.MdiParent
searchForms.Show()

The problem is that searchForms does not stay contained in the mdiMaster
form. I tried the following syntax:
searchForms.MdiParent = Me.MdiParent.MdiParent

which caused a runtime error and hung the application.

Also, I have the mdiMaster IsMdiContainer form property set to true.

Any suggestions? Thanks.
 
J

Jeffrey Tan[MSFT]

Hi,

Thanks for your post.

For this issue, can you provide a little sample project(specific to this
problem) to help us reproduce out your problem? You can attach it in the
reply with Outlook Express.

Normally, I have review your sample code snippet, which should work well.
With your sample repropduce project, I think we can understand your problem
much better.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi jmh,

Yes, normally, we suggest you attach your sample project as an attachment
when replying post(through Outlook Express). This will benifit the entire
community. However, if you still can not attach it, you may directly email
me at (e-mail address removed)(remove the "online.").

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Josh,

I have received your sample project and reproduced out your problem on my
side.

After reviewing your project, I found that it seems the problem occurs in
"applicantion" class. In the btnResults_Click event, you code like this:

Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnResults.Click
Dim FirstNameVal As String = txtFirstName.Text
Dim MiddleNameVal As String = txtMiddleName.Text
Dim LastNameVal As String = txtLastName.Text
Dim SuffixVal As String = txtSuffix.Text
Dim SSN As String = mtxtSSN.CtlText
Me.Close()

Dim searchForms As New searchForms
searchForms.MdiParent = Me.MdiParent 'Not working....
searchForms.Show()
searchForms.txtFirstName.Text = FirstNameVal
searchForms.txtMiddleName.Text = MiddleNameVal
searchForms.txtLastName.Text = LastNameVal
searchForms.txtSuffix.Text = SuffixVal
searchForms.txtSSN.Text = SSN
End Sub

We can see that you invoked Me.Close() method before searchForms.MdiParent
= Me.MdiParent. This is where the problem occurs out: after Me.Close()
calling, Me.MdiParent property will be "nothing".

To get rid of the problem, we only need to place Me.Close method after
Me.MdiParent calling, like this:
Private Sub btnResults_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnResults.Click
Dim FirstNameVal As String = txtFirstName.Text
Dim MiddleNameVal As String = txtMiddleName.Text
Dim LastNameVal As String = txtLastName.Text
Dim SuffixVal As String = txtSuffix.Text
Dim SSN As String = mtxtSSN.CtlText

Dim searchForms As New searchForms
searchForms.MdiParent = Me.MdiParent 'Not working....
searchForms.Show()
searchForms.txtFirstName.Text = FirstNameVal
searchForms.txtMiddleName.Text = MiddleNameVal
searchForms.txtLastName.Text = LastNameVal
searchForms.txtSuffix.Text = SuffixVal
searchForms.txtSSN.Text = SSN
Me.Close()
End Sub
=========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top