Link to home
Start Free TrialLog in
Avatar of EYoung
EYoungFlag for United States of America

asked on

Showing a vb.net form

In vb 6 I can show a form using:
   Form1.show

Or I can show the form modally using:
   Form1.show vbModal

In vb.net that does not work unless I first dim a new form then show:
  Dim MyForm1 as New Form1()
  MyForm1.Show()

However, I can't continue Dim'ing the form as I create multiple copies of the form.  I just want to dim it once and show or hide in the future.

Also need to consider when the user exits the form by clicking the "X" in the control box.

I am new to vb.net and so I hope this is an easily solved problem.  vb.net seems more complicated and verbose than vb 6?

Thanks for the help.
Avatar of Drifter88zxtW
Drifter88zxtW

Make the MyForm1 a Module Level Variable
and instnsiate it in the Form_Load event.

MyForm1.ShowDialog will show the form modaly.

Checking on determing how form is closed
All I could find was that it that the UnloadMode has no equivalent in .net

But im sure there is some way. But I dont know it =)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vxconchangestoformobjectinvisualbasicnet.asp
Avatar of EYoung

ASKER

How do I "Make the MyForm1 a Module Level Variable and instansiate it in the Form_Load event.

Thank you for the other info and like to MS.  I have raised the points.
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private aForm2 As Form2 'This is Module Level.

#Region " Windows Form Designer generated code "

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        aForm2 = New Form2()
    End Sub


    Private Sub frmOpenForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles frmOpenForm2.Click
        aForm2.Show() 'If you want Modaly then aForm2.ShowDialog
    End Sub

End Class
ASKER CERTIFIED SOLUTION
Avatar of Drifter88zxtW
Drifter88zxtW

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EYoung

ASKER

Thank you for taking the extra time to explain that to me.  Although I have several years with vb6, vb.net is quite different and seems more verbose.

I still don't know how to allow the user to click on the "X" in the control box on aForm2 without getting an error like the following after clicking on the button on Form1.


An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named "Form2".


The odd thing is that I get the above error if I call aForm2 using "aForm2.Show" but not if I call using "aForm2.ShowDialog".

Thanks.