I have a VB.NET Windows form created by another developer that needs to be invoked from within my C# application. The VB developer provided a DLL containing the form and the following VB fragment that they use in their VB application to pop the form
Dim objPManager As New PManager.frmPManager
Private Sub btnPManager_Click(& & & &) Handles btnPManager.Click
If File.Exists(FullPath) Then
objPManager.PManagerFuncti
on(FullPat
h)
End If
End Sub
To pop this form myself I added a reference to the PManager.dll in my C# solution (it called the reference PManager) and did the following in the code for my MainForm (MainForm.cs)
PManager.frmPManager pm = new PManager.frmPManager();
pm.PManagerFunction(myPath
);
pm.Visible = false;
pm.ShowDialog();
pm.Dispose();
pm = null;
The constructor for their form appears to show the form by default. I wanted the form modal, so I hid the form and then did a showdialog to get it back as modal. The VB form correctly displays as modal however when you close the VB form the fun really starts...
Any attempt to access my original MainForm, even with something simple like
MessageBox.Show(this, "Hello World", "Debug") results in an ObjectDisposedException on my main form... if I comment out the call to the VB form then this error goes away.
System.ObjectDisposedExcep
tion was caught
Message="Cannot access a disposed object.\r\nObject name: 'S3AUPMainForm'."
Source="System.Windows.For
ms"
ObjectName="MainForm"
I thought there might have been some kind of strange conflict in form names (ie. they used MainForm in their code) so I renamed my form to a random name and it made no difference.
I'm at a complete loss here as to what could be causing this problem.
Start Free Trial