473,465 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to close and show another form??

Hi,

I have my main form1 and I want to close it and then show form2, in VB6 I
used the following code...

unload me
form2.show

in VB.net I got this far

me.close()
form2.show

as it turned out the code does not work! what's the secret in getting it
work?

thanks,

Gary

Nov 20 '05 #1
3 20617
Hi Gary,

Based on experience, windows application will run the Form1(the form
created when you create a windows application) as the main form
When the Form1 closed, ExitThread will be called to clean up the
application. So when you call the form1.close, the application will exit.
If you want to simulate the behavior of VB6, you may try to code below.

Right click on the project in the Solution explorer, and select properties.
Navigate to Common properties/General/Startup Object, set the value to Sub
Main.

Add a module to the project, copy and paste the code[Module1.vb] below to
the module.
Press F5 to run the application too see if this does the job for you.

[Module1.vb]
Imports System.Windows.Forms

Public Module MyApplication
Public formCount As Integer
Public fm1 As Form1
Public fm2 As Form2
Public Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
formCount = formCount - 1
If (formCount = 0) Then
Application.ExitThread()
End If
End Sub
Public Sub Main()
formCount = 0
fm1 = New Form1
formCount = formCount + 1
fm2 = New Form2
formCount = formCount + 1
AddHandler fm1.Closed, AddressOf OnFormClosed
AddHandler fm2.Closed, AddressOf OnFormClosed
fm1.Show()
Application.Run()
End Sub
End Module

[Form1.vb]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
fm2.Show()
'Close form1 and show form2
End Sub

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #2
* "Gary" <sp**@spam.com> scripsit:
I have my main form1 and I want to close it and then show form2, in VB6 I
used the following code...

unload me
form2.show

in VB.net I got this far

me.close()
form2.show

as it turned out the code does not work! what's the secret in getting it
work?


See:

<http://www.google.com/groups?selm=u%23xQOutWDHA.2100%40TK2MSFTNGP11.phx. gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
The problem is that in vb.net all forms are classes so you have to declare
an object
Dim myForm2 as New Form2

and after you can use your code
myForm2.Show()
Me.Close()
Regards
Valeria

"Gary" <sp**@spam.com> ha scritto nel messaggio
news:O8**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have my main form1 and I want to close it and then show form2, in VB6 I
used the following code...

unload me
form2.show

in VB.net I got this far

me.close()
form2.show

as it turned out the code does not work! what's the secret in getting it
work?

thanks,

Gary


Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
7
by: Nikki | last post by:
Hi, Can anybody help me, i want to prevent windows to close my winform of ..NET application, when user presses Alt+F4
3
by: Kimelia | last post by:
I want to create something like wizard, which will ask one question and proceed to the next question. So, it's like showing Form A (Question 1), then when the user press "Next" button, I want to...
1
by: Adam Honek | last post by:
Why oh why has MS changed so much in VB.NET I can't even figure out how to show/close a form as formname.show() doesnt work and the following doesn't either: formname.activeform.close() (or...
8
by: mattgcon | last post by:
I have a popup form within my application that I want to show for only about 10 seconds. On this form by the way has an AVI that plays. I want the form to popup on click of a button and close after...
2
by: Del | last post by:
I have a popup form that consist of a single field called EnteredBy and a Subform that has three fields. The popup form also has a button in the Form Footer called close. In the On Click event I...
3
by: agarwalsunitadhn | last post by:
hello i am working in C#.net. I want to know how to close one form and show another one. I had done the following code this.Hide(); MainForm frm = new...
5
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I am showing a form by ShowModal(). I put a button on that form. When a user clicks the button a MsgBox will show with question "do you want to close?" yes/no. How to handle the situation: - user...
4
by: maubarra | last post by:
Hi, I have a problem here I hope someone can help me out. I have this application in which I show information about workplans. It has a Main Form which show the general information and the activites...
5
by: Kapil Choubisa | last post by:
Hi! I am creating a application for Windows Mobile using C#. I am a new guy in Windows Mobile. I am facing a problen. I have 3forms. on the form 2 I code on click of back menu. form1 frm=new...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.