Open and Close Winform

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 84
Reputation: rinoa04 is on a distinguished road 
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Open and Close Winform

 
0
  #1
Oct 1st, 2007
Hello,
I am currently designing a system using C# winform. However, there is a problem in opening and closing multiple winform. For example, when i run the application, a login form will appear on top of the main form. The main form will only be enabled after user enter the valid username and password. When user login with a valid username and password, the login form will be close and the main form will be enabled.

Since I run the application using login form. When I close the login form, the whole application will be closed. If I hide the form then the application will still be running eventhough I closed all the forms.

Does anyone know how to solve this problem or any better recommendation?
Thank you.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Open and Close Winform

 
0
  #2
Oct 1st, 2007
That's for sure, let the main form to be the start and in it constructor call the login form after valid login close it, the application won't close.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 84
Reputation: rinoa04 is on a distinguished road 
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Open and Close Winform

 
0
  #3
Oct 1st, 2007
Thank you for the help. But there still exist problem. The application will still be closed when the main form is closed.

However, it can be solved using MDIParent and Child Form. But can it be done without using MDI. I mean the design concept similar to webform. When user click on a button, then it will open the selected form and close the previous form in which means opening one form at time.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Open and Close Winform

 
0
  #4
Oct 2nd, 2007
Main form means when you close it that's mean you close the application.
1- MDI won't work in modal dialog mode.
2- User will go through the main form without looking to your login form.

what supposed to done is to run the main form you may hide it then run the login form after success login show the main form.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Open and Close Winform

 
0
  #5
Oct 2nd, 2007
It sounds like maybe you have a couple things backwards.
Your Main Application should not be the login screen. Instead, create a Winform application, and add the Login WinForm to it. Then when the main application loads (Load Event) , create the Login form and show it modal, and get the result from the Login form's DialogResult.
Login lg = newLogin();
if (lg.ShowDialog() != DialogResult.OK)
  Close();
 
... Do your main Application stuff ...
You can do your vierification tasks inside your Login form or in the main form. If they hit the cancel button or exit any other way than the Accept button, set the Login form's DialogResult to Cancel. If they Click your accept button, then (optionally do checks) set the DialogResult to Ok to get back to the main application.
Let the Main form continue if the DialogResult is Ok, otherwise Close the main application.

--Jerry
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: merdan144 is an unknown quantity at this point 
Solved Threads: 0
merdan144 merdan144 is offline Offline
Newbie Poster

Re: Open and Close Winform

 
0
  #6
Jun 5th, 2008
  1. this.Hide(); //hide login form
  2. Form1 mainForm = new Form1;
  3. mainForm.ShowDialog(); //important to use ShowDialog(); so that
  4. this.Close(); //login form closes only when mainForm closes.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Open and Close Winform

 
0
  #7
Jun 5th, 2008
This thread is closed (or should be)
Started in Oct 2007, and the thread starter has not closed this thread.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC