Jump to content
xisto Community
Sign in to follow this  
bob3695

Switching Forms - VB.NET Some VB.NET Basics

Recommended Posts

When I started coding in VB.NET I was unsure of how to switch forms at a click of a button or any other event. So for anyone with the same problem this is for them.

First you must have at least two forms in the project. If you do not know how to add forms to a project heres how:

1) Under the "Project" Menu select "Add Windows Form..."

2) In the dialog box that pops up near the bottom you will see "Name:" with a textbox beside it. In the text box type the name of the new form. For this example we will just use the default name, "Form2.vb"

3) Click "Open"

You now have two forms in your project. Now to switching forms.

1) Double Click on Form1 in the "Solution Explorer".

2) Add a button to the form.

3) Double-Click on the button. The Code window should show up.

4) In the code window type:

Dim Form as new Form2	Form.Show
5) That show the form. This step is not required. Use only if you want to hide the first form.
Me.Hide
Thats it! I know it is very basic but there are some people out there that need to learn the basics.

Thanks,
Email me at bob3695@gmail.com

Share this post


Link to post
Share on other sites

4) In the code window type:

Dim Form as new Form2Form.Show
5) That show the form. This step is not required. Use only if you want to hide the first form.

Me.Hide

you can also unload your form instead of just hiding it!

Private Sub Command1_Clickme.unloadEnd Sub
should be enough to properly close the form. there is more on unloading forms and how to do it in this topic >> http://forums.xisto.com/index.php?showtopib.net+unloading

 

when you hide a form you are leaving it in the momory just hidden from the user. now this is ok for smaller applications and you ca get away with it. but if you are making applications that need memory and lots of it, or you are building for computers that may not have much memory, you are going to need the memory that the hidden form is taking! unloading the form takes back this memory and can use it elsewhere.

 

also, the only time visual basic will close the program properly is when all the forms are closed, if you still have open forms (they are hidden but still open!) visual basic will not close the program and it will continue to run! This is not a good thing to get into! it is alright when you are in a debug environment and you can just press the 'stop' button to end debugging! but what happens when there is an end use that loads the program, uses it then closes it, the program is still running in the background, again using memory!

 

hiding forms though can still have its advantages! if you were planning to use information on that form later in your program and didn't want to put them into public variables, then you can leave the form running just to keep the information, then once its been used to moved to a better place, you can close the form.

 

if you do hide forms all the time and want to close a program properly you can use one line of code to close all your hidden forms and end the program.

Private Sub Command1_ClickendEnd Sub
is all you need to close the program and get rid of all the hidden forms

 

good luck programming

-jimmy

Share this post


Link to post
Share on other sites

Loading and Unloading Forms

Switching Forms - VB.NET

 

Using me.Close in VB 2005 closes all forms in short ending the whole program

 

-reply by Sledge

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.