We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Close in load event in child form

this sample fire exception "Cannot call Close() while doing CreateHandle()." 1. What is the cause of this error? 2. Is there any solution and if yes, what it would be? --- in main form Dim frm As New Form2 Try frm.MdiParent = Me frm.Show() Catch ex As Exception MessageBox.Show(ex.Message) End Try --- in child form Dim bUslov As Boolean Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load '---- code bUslov = True ' ----- code If bUslov Then Me.Close() End If End Sub

1 Reply

MJ Michal Jirku April 3, 2004 06:17 AM

Yoy can not create Handle and then call Close() method. Try to set "frm.MdiParent = Me" after show method, outside try & catch block. >this sample fire exception "Cannot call Close() while doing CreateHandle()." > >1. What is the cause of this error? >2. Is there any solution and if yes, what it would be? > >--- in main form > > Dim frm As New Form2 > Try > frm.MdiParent = Me > frm.Show() > Catch ex As Exception > MessageBox.Show(ex.Message) > End Try > >--- in child form > > Dim bUslov As Boolean > > Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load > > ''---- code > > bUslov = True > > '' ----- code > > If bUslov Then > Me.Close() > End If > > End Sub > > > > > >

Loader.
Live Chat Icon For mobile
Up arrow icon