|
|
|
|
![]() ![]() |
Jun 13 2005, 03:24 AM
Post
#1
|
|
|
Member [ Level 1 ] Group: Members Posts: 35 Joined: 10-June 05 Member No.: 6,038 |
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 |
|
|
|
Jan 17 2007, 12:41 AM
Post
#2
|
|
|
Living at the Datacenter Group: [HOSTED] Posts: 708 Joined: 30-June 06 From: Australia Member No.: 14,219 myCENTs:76.93 |
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 is all you need to close the program and get rid of all the hidden formsend End Sub good luck programming -jimmy |
|
|
|
Jul 23 2008, 12:41 PM
Post
#3
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
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 |
|
|
|
![]() ![]() |
Similar Topics
| Topics | Topics | |
|---|---|---|
|
|
|
|
Lo-Fi Version | Time is now: 2nd December 2008 - 05:44 PM |