I get the following error:
**************
An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: Cannot call Close() while doing CreateHandle().
**************
When executing the following code after frm2 opens and the user simply presses the Cancel
button to close the dialog form which also should close the calling form (frmAssembly).
In other words there is no way to continue with frmAssembly form without logging in.
Private Sub frmAssembly_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm As New frmMain
sqlConn.ConnectionString = frm.sqlConn.ConnectionString
frm = Nothing
gstrProdTrkNo_Prev = "0"
Dim frm2 As New frmGrpLogOn
frm2.ShowDialog()
Select Case frm2.DialogResult
Case DialogResult.OK
With Me
intGrp_ID = frm2.Grp_ID
.tbGrpName.Text = frm2.GrpName
dtLogInDT = frm2.GrpLogInDT
.rbDone.Checked = True
.tbProdTrkNo.Focus()
End With
Case DialogResult.Cancel
Me.Close() '<--ERROR OCCURS ON THIS LINE
Exit Sub
End Select
End Sub
</code

Error when attempting to Close a form
rajuraju
vivi_0606
There is no open event in Windows .NET using VB.NET.
NewDBA
pongopiprakash
Actually the frmAssembly is a child form in a midi application which is opened from a menu item on the main form. So I just move this code to the menu item click event. If the user cancels the dialog form, I simly do not show frmAssembly.
Apparemtly the root problem is that attempting to close the form in Load process errors because the Close event has not been formed yet Whatever happened the to "Open" event which was cancellable.
raindrops123
http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbcn7/html/vbconHelloWorld.asp
Something along the lines of...
Shared Sub Main()
Dim form2 As Form2
form2 = New Form2()
If (form2.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
Application.Run(New Form1())
End If
End Sub