473,761 Members | 10,057 Online
Bytes | Software Development & Data Engineering Community
+ 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 20716
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(By Val sender As Object, ByVal e As EventArgs)
formCount = formCount - 1
If (formCount = 0) Then
Application.Exi tThread()
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) 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.co m> 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%2 3xQOutWDHA.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.co m> ha scritto nel messaggio
news:O8******** ******@TK2MSFTN GP12.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
74132
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 Form1.Visible = False Load (Form1)
7
7897
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
19234
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 close Form A (Question 1), and show Form B (Question 2). Sorry to ask if this is too simple, as I am still learning C#. Thanks and have a nice day.
1
1497
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 show) doesn't seem to work but will compile. Thanks, Adam H.
8
19760
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 10 seconds automatically but can't figure out how to do it, does nayone know how to do this?
2
4329
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 have the following code. DoCmd.Close I want the EnteredBy field to be a required field. So in the On Exit event for that field I have the following code.
3
2407
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 MainForm(); frm.Show(); frm.Focus(); frm.Activate(); but when i close the last form activated then still it shows that the application is running. how can i completly close the first form
5
4983
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 clicks "yes" - the form closes - user clicks "no" - nothing happens I have problem with that. It seems that assigning property of button.DialogResult wokrs ok only for the first time (in designer generated code and any longer)
4
1243
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 that are going to take place during the execution. The application has the ability to "attach" documents to the activities. I have created another form (and MDI form) that I use to show the documents (pdfs) when a user clicks on one of the...
5
2704
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 form1; form2 frm2=new form; frm2.close(); frm1.show();
0
9333
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10107
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7324
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5214
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3863
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 we have to send another system
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.