How to show, load a form in VB.NET?

  • Thread starter Thread starter Tim Smallwood
  • Start date Start date
T

Tim Smallwood

Hi,

This is probably a stupid question, but I can't seem to get a form to
show / load? In the older versions of VB I'd use frmMyform.show / load
myForm, etc? I looked at the help file and it showed me how to create a
new form in code and then load it, but I want to load a form when a user
clicks a button.. and hide the form that currently has focus..? I can't
seem to find this simple task in the help file.. Any help would be
greatly apprecaited..

Thanks

Tim
 
'Form name to be opened: myFor

'Inside on click of button su
Dim frm as New myFor
myForm.Show(


Hope this helps.
 
Tim Smallwood said:
This is probably a stupid question, but I can't seem to get a form
to show / load? In the older versions of VB I'd use frmMyform.show /
load myForm, etc? I looked at the help file and it showed me how to
create a new form in code and then load it, but I want to load a form
when a user clicks a button.. and hide the form that currently has
focus..? I can't seem to find this simple task in the help file.. Any
help would be greatly apprecaited..

To show a Form:
dim f as new Form2
f.Show 'or f.ShowDialog

If you want to hide a Form and show another one, you shouldn't use a Form as
the startup object in the project properties. This should only be done if a
Form is shown from the start til the end of the application. Instead, use
your own Sub Main as the startup object:

sub main
dim f as new Form1
f.show
application.run()
end sub

To show another Form and hide the start Form:
dim f2 as Form2
f2 = new form2
f2.show
Me.visible = false

To stop the application - this doesn't happen automatically when the start
form closes because the startup object is not a Form - you must call
Application.ExitThread.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
That code is only for a new form right? I want to open an existing form
by name? Thanks so much..

Tim
 
* Tim Smallwood said:
This is probably a stupid question, but I can't seem to get a form to
show / load? In the older versions of VB I'd use frmMyform.show / load
myForm, etc? I looked at the help file and it showed me how to create a
new form in code and then load it, but I want to load a form when a user
clicks a button.. and hide the form that currently has focus..?

<URL:http://www.google.de/groups?selm=u#[email protected]>
 
Thank you so much.. Can't I exit the application by using "End" ? Just
cuirous..


Tim
 
I guess coming from a NON programming background, I really liked the way
it worked in VB6.0.. It was a whole lot easier, .. I realize there's a
good reason for this, but it's way to complicated to have to create an
instance of a form to just show a form! Yikes! hehe.. Thanks so much..

Tim
 
I've decide to use the Tab Control in this case to save the memory and
the trouble of opening and closing several forms as the scope of the
project has just changed and I don't want to open and close so many
forms.. I'm curious if more memory is used with one form and a tab
control, or by having several forms and hiding and showing them?

Tim
 
Tim Smallwood said:
I guess coming from a NON programming background, I really liked the
way it worked in VB6.0.. It was a whole lot easier, .. I realize
there's a good reason for this, but it's way to complicated to have
to create an instance of a form to just show a form! Yikes! hehe..
Thanks so much..

It might have been a little easier but at the cost of being less flexible.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
If you are holding all the forms open in memory and using Show/Hide,
then a single form with a tab control will use less memory. If you are
opening and closing the forms, then multiple forms uses less memory, at
the expense of some processing time.

Do not get too worried about the difference between the two, unless you
are seriously short of resources, there is very little difference
between the two methods. Your client's requirements are far more
important.
Thank you so much.. Can't I exit the application by >using "End" ?

Yes, same result.

Armin wrote :
If you want to hide a Form and show another one, you >shouldn't use a
Form as the startup object in the project >properties. This should only
be done if a Form is shown >from the start til the end of the
application. Instead, >use your own Sub Main as the startup object.

I agree. I always use Sub Main, even if there is only one form as this
gives far greater coding flexibility.

VB.Net needs a different mind set to VB6. I suggest you get used to
declaring forms and classes etc, it is well worth the effort to get the
most out of .Net.

As a suggestion, make sure there is as little code in the form(s) as
possible. Put all the logic in classes and call the functions as needed.
This makes the code easier to maintain and debug.

Do you know someone who codes in C++ or C#? If so, pick their brains
about how they would structure a similar application.

James
 
Thank you so much.. Can't I exit the application by >using "End" ?

Application.ExitThread()

eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top