EYoung
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.
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.
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
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
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.
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.ObjectDisposedExce ption' 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.
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.ObjectDisposedExce
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.
and instnsiate it in the Form_Load event.
MyForm1.ShowDialog will show the form modaly.
Checking on determing how form is closed