|
-
February 7th, 2008, 01:20 AM
#1
how to close the forms....
Hi all,
I have one form with name HOME......which contains a link to CONNECT form...
And am having another form let it be CONNECT it contains a link....
The link navigate to HOME FORM....
but i want to do like this..if i click link in CONNECT form it must close the
previously opened HOME form and CONNECT form and i want open HOME form newely....
plz s****t me..
thanks,
-
February 7th, 2008, 02:33 AM
#2
Re: how to close the forms....
Are you sure you want this kind of behaviour?
It's quite difficult to implement. Why? Because did you think where you are going to store the CONNECT forms variable which you instantiate in HOME form?
-
February 7th, 2008, 02:41 AM
#3
Re: how to close the forms....
I will just show my code ...
in main form i.e., in HOME
Code:
CONNECT cnt = new CONNECT();
cnt.show();
linklabel.LinkedVisited=true;
same in CONNECT form also instead of creatinng connect object i created home object....
-
February 7th, 2008, 02:49 PM
#4
Re: how to close the forms....
I'm not sure to understand what you want, but if you check the default generated file program.cs in the main, there is a line like that
Code:
Application.Run(new Form1());
So, what you could do is just a kind of manager that will keep the next form to run.
Code:
Form f = myFormManager.GetNextForm();
while (f != null)
{
Application.Run(f);
f = myFormManager.GetNextForm();
}
-
February 8th, 2008, 02:26 AM
#5
Re: how to close the forms....
 Originally Posted by chinnaraj
Hi all,
I have one form with name HOME......which contains a link to CONNECT form...
And am having another form let it be CONNECT it contains a link....
The link navigate to HOME FORM....
but i want to do like this..if i click link in CONNECT form it must close the
previously opened HOME form and CONNECT form and i want open HOME form newely....
plz s****t me..
thanks,
Upload and attach your code here...
-
February 8th, 2008, 11:18 AM
#6
Re: how to close the forms....
 Originally Posted by chinnaraj
same in CONNECT form also instead of creatinng connect object i created home object....
If you are creating in a chain then thehome creates a cnnect and the connect again a new Home and ... this will lead to a nice overflow error when you do this in the constructor and will per sure lead into troubles. WRONG DESIGN.
As mentioned before in the program.cs ceate a dictionary here you store all your Forms. Give them a key so you are able to differ between them and then use the key to access your dictionary to get a pointer to your Forms, which you just in the moment need to use. so you are able to easily switch between your Forms. Maybe you should think about having an MDI Form as Parent and MDI children as your Forms. Closing a Form in this case needs to delete it in the Dictionary too !
If you have too much troubles show your project as a zip file ( dont include any bin, nor object files ) and we will do a repair for you.
 Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
February 8th, 2008, 11:58 AM
#7
Re: how to close the forms....
I think what he wants to create is a "Wizard", like an installer or something which takes you from Step 1 to Step 2 to Step 3, etc...
The way I would do it is simply create each 'form' (it can be a user control, a form, or anything else you want) as an individual entity that handles whatever particular functionality it needs. I would also use a common base class if there were going to be some common functions, such as a previous, next or cancel buttons.
Then I would just make the main application object a big state machine (which can be done directly as methods, delegates, lists, etc...) and it would invoke the first form and subscribe to it's next / previous / cancel events. It would hold all the data that is gathered and be responsible for hiding / showing the different forms. It it would know what was next or what came before it. It could make decisions such as skipping form #5 if it is not relevant and stuff like that.
Specifically, I would make each one of these "forms" a user control and the Main form would just have a big panel that it put these user controls in as needed. The main form would the common functions like next/previous while each user control was only a UI to gather whatever information from the user that it needed.
You could use a factory that could take a result from one of these user control and make the next user control for you. For example, form "Home" had a button to "Connect" or a button for "Settings" when the user clicked either of these, it could set a property (or event) that had a "NextForm" string. That string could be fed into the factory which would then construct the instance for the next form.
If you do it that way, then the main form code stays simple and dumb (which is good). If you wish to add / remove / change a transition from one of these user controls, you just need to edit that one user control code without touching anything else. IE: You want to add an "Advance Settings" to the "Home" form, you just add the button which sets the "NextForm" string and you are done.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|