
One form "show" another form
I presume "Dim frm2 As New frm2()" should say "Dim frmPortfolio As New
frm2()"?
You only create the instance of frm2 when frmMain is instantiated. If you
then close frm2, the variable frmPortfolio is no longer valid, and is
pointing to a closed (or discarded) form.
You could use something like
Private Sub pic1_Click(ByVal _
sender As System.Object, ByVal e As _
System.EventArgs) Handles pic1.Click
If frmPortfolio.IsDisposed Then _
frmPortfolio = New Form2()
frmPortfolio.Show()
End Sub
Cheers,
Jason
----------------
I am having trouble making one form "show" another form. frmMain has a
picturebox that when clicked should load frm2.
Public Class frmMain
Inherits System.Windows.Forms.Form
Dim frm2 As New frm2()
Private Sub pic1_Click(ByVal _
sender As System.Object, ByVal e As _
System.EventArgs) Handles pic1.Click
frmPortfolio.Show()
End Sub
End Class
This works great for the first time the user clicks on the picturebox. It
shows the second form just like it should, and it prevents the user from
firing off multiple copies of the secondary form. But if the user closes
the secondary form, and then clicks the picturebox again on the main form,
it will not load the secondary form again.
The second time the user clicks the picture, after having closed frm2, it
throws this error:
An unhandled exception of type 'System.ObjectDisposedException' occurred in
system.windows.forms.dll
Additional information: Cannot access a disposed object named "frm2".
Any ideas?
Thanks,
Cliff Cavin
Columbus, Ohio
http://BubbaDogSoftware.dnsalias.net