Close in the load event on 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
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Dim frm As New Form2
Try
frm.MdiParent = Me
frm.Show()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'------- 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
|