Nov 22, 2009

Switching Forms - VB.NET - Some VB.NET Basics

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

Switching Forms - VB.NET - Some VB.NET Basics

bob3695
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:
CODE
    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.
CODE
    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

 

 

 


Comment/Reply (w/o sign-up)

Jimmy89
QUOTE
4) In the code window type:
CODE


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.
CODE


Me.Hide



you can also unload your form instead of just hiding it!
CODE
Private Sub Command1_Click
me.unload
End Sub

should be enough to properly close the form. there is more on unloading forms and how to do it in this topic >> http://www.astahost.com/index.php?showtopi...b.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.
CODE
Private Sub Command1_Click
end
End Sub
is all you need to close the program and get rid of all the hidden forms

good luck programming
-jimmy

 

 

 


Comment/Reply (w/o sign-up)

iGuest-Sledge
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

Comment/Reply (w/o sign-up)

(G)ME.Thanks!!
Replying to bob3695 Thanks a lot! This was so simple but I searched everywhrere for how to do this and couldn't find a straight forward answer. This solved my problem easily!
 
Thanks,
 -reply by ME
 
 

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for switching, forms, vb, net, vb, net, basics
advertisement



Switching Forms - VB.NET - Some VB.NET Basics

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com