473,287 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

i want to go to form2 on buttonclick of form1 and close form1 at the same time

i want to move to form2 on buttonclick at form1 and at the same time i want to close form1
Jul 26 '10 #1
1 1492
Joseph Martell
198 Expert 128KB
The simplest way to accomplis this is to add this to a button event handler in form1:
Expand|Select|Wrap|Line Numbers
  1. frmTest2 myForm = new frmTest2();
  2. myForm.Show();
  3. this.Close();
  4.  
but this only works if form1 is not the main application form. If form1 is the main application form then this merely kills the application.

To do this with all forms and have it work with the main application form you would have to add a property to your forms, say NextFormToShow, that returns a form object. Then whatever code is checking for form1 to be closed would have to show the next form.

In Program.cs, that would mean having something like the following lines:

Expand|Select|Wrap|Line Numbers
  1.             frmTest mainForm = new frmTest();
  2.             Application.Run(mainForm);
  3.  
  4.             //executes after mainForm has closed
  5.             Form nextForm = mainForm.NextFormToShow;
  6.             Application.Run(nextForm);
Jul 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Kitchen Bin | last post by:
HELP PLEASE!! The C# Visual Studio IDE is failing to load an inherited form into the IDE from a base form when I add items to an array property of a user control on the base form. That sounds...
1
by: Richard | last post by:
Hello there, I have a form that is called from a Sub Main procedure using application.run(Form1). On my main form there is a button to open an instance of Form2 and then at the same time hide...
3
by: Karan | last post by:
I am calling finalize when form2 loads and deactivates form1 which closes form1. However, same thing is not happening in form2 because finalize is already called. Does anybody has solution to it....
5
by: Sudha Pune | last post by:
Hi all Just i want to close the form1 when i click the button1 on form1 and the same time i want to load the form2 on the same event. And i dont want to hide the form1 instead of close....
4
by: Jason Huang | last post by:
Hi, In my C# windows form project, how do I in a formA open another formB, and close formA when formB is opened? Thanks for help. Jason
2
by: yogendrabmishra | last post by:
Hello guys, I am trying to use this function to close window and i want this function should be compatible with all browsers but it is working only with IE and Opera not with others. So please...
0
by: Jesper | last post by:
Hi Im doing a stone, scissor and bag game, (sten, sax och påse, for the swedish ppl). Form1 is for just writing your name and push a button and when you push the button its should close form1...
3
by: =?Utf-8?B?RGF2ZVA=?= | last post by:
I've got a situation in a VB 2003 Windows application with an MDI form and a child form. In certain situations, when the child is closed by the user, I also want to close the MDI parent. Is there...
2
by: egross73 | last post by:
Hello, I was wondering if there was a way to make a tkinter window open and close over time. I would probably use the time module and time.sleep() to make it wait, but could I use a command to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.