| | |
Problem Travelling Through Windows Forms
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Hello there fellow members.
I have two windows forms, and they call each other.
- Form 1 has a button that calls Form 2.
- Form 2 does not have an exit button, but rather a button that goes back to Form 1.
- Form 1 is the main form and the program is terminated from it.
Now, I have a background algorithm in Form 1 which must not work when going to Form 2, but when I go back from 2 to 1, that algorithm should work again.
So, I did the following:
- Code of the button that takes me from Form 1 to 2:
- Code of the button that takes me back from 2 to 1:
However, this leads to a problem of Form replication. If I go through the forms back and forth a little bit, then back to the main form and close the application; some artifacts remain in the background. Instances of the application itself remain working (can be shut off from the Task Manager), so how do I make sure that once Form 1 is closed, the application and all extra instances created during this Form traversal are terminated?
Thanks in advance!
I have two windows forms, and they call each other.
- Form 1 has a button that calls Form 2.
- Form 2 does not have an exit button, but rather a button that goes back to Form 1.
- Form 1 is the main form and the program is terminated from it.
Now, I have a background algorithm in Form 1 which must not work when going to Form 2, but when I go back from 2 to 1, that algorithm should work again.
So, I did the following:
- Code of the button that takes me from Form 1 to 2:
C# Syntax (Toggle Plain Text)
Form2 frm2 = new Form2(); frm2.Show(); this.Hide();
- Code of the button that takes me back from 2 to 1:
C# Syntax (Toggle Plain Text)
Form1 frm1 = new Form1(); this.Close(); frm1.Show();
However, this leads to a problem of Form replication. If I go through the forms back and forth a little bit, then back to the main form and close the application; some artifacts remain in the background. Instances of the application itself remain working (can be shut off from the Task Manager), so how do I make sure that once Form 1 is closed, the application and all extra instances created during this Form traversal are terminated?
Thanks in advance!
Ask a stupid question; get a stupid answer.
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
When creating Form 1, use this method:
This should set Form 1 as the main window of the program, and should terminate the program when it is closed.
Note: This calls the
C# Syntax (Toggle Plain Text)
Application.Run(new Form1());
Note: This calls the
ShowDialog() method of the form after the constructor. I am using this line in my Program.cs file, but artifacts of Form1 still remain in the background after I go back from Form 2 to Form1.
Just to clarify, Form 1 is indeed the main window and the program terminates when it is closed; IF I close it before going back and forth between Form1 and Form2 (Going back between them creates hidden Form1 instances).
Just to clarify, Form 1 is indeed the main window and the program terminates when it is closed; IF I close it before going back and forth between Form1 and Form2 (Going back between them creates hidden Form1 instances).
Ask a stupid question; get a stupid answer.
•
•
Join Date: Aug 2009
Posts: 15
Reputation:
Solved Threads: 1
Hi
When you want to open the form 2 pass an instance of form1 in the form 2 constructor.ie in the button that shows form2 code should be;
In the form 2 constructor get that instance of form1 an asign it to a variable of type Form1 ie in Form2;
When you want to open the form 2 pass an instance of form1 in the form 2 constructor.ie in the button that shows form2 code should be;
C# Syntax (Toggle Plain Text)
Form2 frm2 = new Form2(this); frm2.Show(); this.Hide();
C# Syntax (Toggle Plain Text)
Form1 = MainForm public Form2(Form1 InputForm) { MainForm = InputForm; } Then in the button that takes you to Form1 insert foll code MainForm.Show();
Last edited by John A; Aug 6th, 2009 at 2:39 am. Reason: added code tags
![]() |
Similar Threads
- update time in windows forms (C#)
- Drag and drop from windows forms to desktop and windows explorer (C#)
- autoscroll is not a member of Systems.Windows.Forms.Panel (VB.NET)
- pointers to windows forms (C)
- Windows Forms Question (C#)
- Massive Problem - Cant Start Windows. (Windows NT / 2000 / XP)
- Using Windows XP Visual Styles with Controls on Windows Forms (VB.NET)
- Problem installing windows 2000 professional (Windows NT / 2000 / XP)
- Displaying pictures on Windows Forms using subprocedures in VB.NET (VB.NET)
- Problem Installing Windows XP PRO (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: Problem in inserting the data
- Next Thread: ListView number formatting
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development dll draganddrop drawing encryption enum event excel file finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser wia windows winforms wpf xml





