Visual Studio 2008 window form closes immediately after opening
Within my Visual Studio 2008 VB.Net project I am opening multiple forms after setting the form (that is opening) to be an mdichild of the main form. This works in really well in most of my forms except one. I am doing the exact same thing for all of them.
Basically I declare the new form:
Using frm As New frmName() With {.variableName = currentVariable}
frm.MdiParent = Me.MdiParent
frm.openForm()
End Using
Within the openForm
subroutine in the form code I have:
Public Sub openForm()开发者_运维问答
InitializeDataSources()
... ...
Me.Show()
End Sub
I know this works because if I remove frm.MdiParent = Me.MdiParent
in the main form and change Me.Show()
to Me.ShowDialog()
in the child form then it works perfectly. Right now (for only one form) it shows the form for only a second (looks like a flicker when staring at the program) and then closes it.
What should I do to fix this?
Don't know what USING
is for in VB, but in C# it is disposing the object created by the statement when the execution exists the block.
If the purpose is the same, then this is the answer: you are creating the form:
Using frm As New frmName()
then you show it but when
End Using
is executed your form will be disposed, that is, closed.
精彩评论