Kyra Kyra - 1 year ago 167 Question

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
End Using

Within the
subroutine in the form code I have:

Public Sub openForm()
... ...
End Sub

I know this works because if I remove
frm.MdiParent = Me.MdiParent
in the main form and change
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?

Adi Adi
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download