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

free web hosting
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

 

 

 


Reply

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

 

 

 


Reply

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

Reply


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*

Recent Queries:-
  1. vb.net program does not close - 0.35 hr back. (1)
  2. how to close a vb.net form in button click - 2.51 hr back. (1)
  3. hide form vb 2005 - 3.25 hr back. (1)
  4. loding form in vb.net - 4.83 hr back. (1)
  5. show form in vb.net - 6.23 hr back. (1)
  6. vb.net switching form control - 7.49 hr back. (1)
  7. "visual basic" "hide form" - 8.85 hr back. (1)
  8. vb.net switch to new forms - 10.05 hr back. (1)
  9. vb.net switch web forms - 10.25 hr back. (1)
  10. vb close form click away - 14.23 hr back. (1)
  11. forms in vb.net - 18.22 hr back. (2)
  12. vb.net add form to project - 18.80 hr back. (1)
  13. show or hide form vb - 19.00 hr back. (1)
  14. vb.net - close a form - 20.82 hr back. (1)
Similar Topics

Keywords : switching, forms, vb, net, vb, net, basics

  1. New Features In Visual Studio 2005 Windows Forms
    (1)


      Looking for switching, forms, vb, net, vb, net, basics






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




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