Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok guys here my problem and it's getting annoying.

 

The MDI Parent form

 

Private Sub MenuItem2_Click
Dim ma As New Form2()
ma.MdiParent = Me
ma.Show()
End Sub

 

The Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       Dim ha As New Form3()
       If ha.ShowDialog() = DialogResult.Cancel Then
           Me.Close()
       End If

End Sub

 

This works fine when it's not inside an mdi parent

but when it does like this example i get the error

 

Can't call Close() while doing CreateHandle()

 

Any hints ? any Ideas why is this happening ? and also any solutions ?

 

And another one why i can't the the mdiparent to a dialog? i get the exception:

 

Forms that are not top level forms cannot be displayed as a modal dialog. Remove the form from any parent form before calling showDialog.

 

I understand what is says but why ?

is there any way to override this ?

  • *Experts*
Posted

Your first problem is that you can't call Close within the Load event. You can try moving the code to your constructor, but I'd rethink your strategy on forms first. For example, maybe the MDI form should be showing Form3 and if it's not Cancel THEN show Form2.

 

If you set the MDIParent property, you're telling Windows that this will be a child window, to be placed "inside" of an MDI Parent. It can't be inside AND be a modal window. Basically, if you're a child window, set the MdiParent property to the parent form and call Show. If you're modal, don't set MdiParent (or set it to Nothing if you already set it to a form), then call ShowDialog.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted
thanks guys, the thing is that in this project i have has about 60 forms and dialogs, and it's quite confusing to change the call for them, besides some of the forms have the dialog in the load in case the value that is needed is not passed from the pervious form, so it's kind of optional which makes it a bit comlicated. Anyway thanks again and any other ideas are welcome.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...