Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading Forms - And not showing?

Status
Not open for further replies.

ConfusedPerson

Instructor
Feb 25, 2003
7
GB
Hello
I'm moving from VB6 to VB.NET and seem to find the simpler elements the hardest to get around. Would anyone know how to load a form in order to get it into memory but not cause it to be made visible? The VB6 equivalent is:

Load Form1

Many thanks in advance for any replies.
 
dim aForm as new MyForm
aForm.show()

MyForm is the form you created.
 

Show() method will display the form. you need to use Hide() method so that it is not displayed.

For instance you want to load Form2 on Click of a Button on Form1:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2()
frm.Show()
frm.Hide()
End Sub


To test the above create a TextBox on Form2 and enter some text into it on design time. Now call the click event as follow:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2()
frm.Show()
frm.Hide()

'This will display a MessageBox containing text
'from the TextBox on Form2, which is loaded
'but hidden
MessageBox.Show(frm.TextBox1.Text)
End Sub


 
Thanks for replying. I'm sure the frm.show followed by frm.hide will work - will try it out a little later, but must admit I don't really feel too impressed with how VB.NET does this. Seems like a bit of a workaround rather than a proper solution. What was the problem with just keeping the LOAD statement for doing this or else having a load or open method for a form, like the close method which as i understand it, is like the unload statement.
Anyway - that's a gripe at the product!! I appreciate the replies on the matter.

Kind Regards

 

As I understand it, VB.net does not support implicit object creation (which was a pain anyway...) and the form is therefore created and loaded into the memory when the 'new' keyword is used.

This little test shows that the form is indeed in memory without using any show/hide tricks (but it does not demonstrate that VB.net does not support implicit object creation).
----------------------------------------------
Dim f As New Form()
Dim t As New TextBox()
f.Controls.Add(t)
t.Text = "hello"
MessageBox.Show(f.Controls(0).Text)
--------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Hi
Thanks for that. It does make the whole loading/unloading, showing/hiding a lot clearer.
Just have to try it all out now.
Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top