otherside Posted April 14, 2003 Posted April 14, 2003 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 ? Quote
*Gurus* divil Posted April 14, 2003 *Gurus* Posted April 14, 2003 Why don't you just not even load the MDI child unless ShowDialog returns ok? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted April 14, 2003 *Experts* Posted April 14, 2003 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 Quote "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
otherside Posted April 14, 2003 Author Posted April 14, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.