944,133 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 38426
  • C# RSS
Oct 1st, 2007
0

Open and Close Winform

Expand Post »
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.
Similar Threads
Reputation Points: 52
Solved Threads: 4
Junior Poster in Training
rinoa04 is offline Offline
84 posts
since Sep 2006
Oct 1st, 2007
0

Re: Open and Close Winform

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.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Oct 1st, 2007
0

Re: Open and Close Winform

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.
Reputation Points: 52
Solved Threads: 4
Junior Poster in Training
rinoa04 is offline Offline
84 posts
since Sep 2006
Oct 2nd, 2007
0

Re: Open and Close Winform

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.
Featured Poster
Reputation Points: 480
Solved Threads: 276
Postaholic
Ramy Mahrous is offline Offline
2,189 posts
since Aug 2006
Oct 2nd, 2007
0

Re: Open and Close Winform

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
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006
Jun 5th, 2008
0

Re: Open and Close Winform

C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
merdan144 is offline Offline
1 posts
since Jun 2008
Jun 5th, 2008
0

Re: Open and Close Winform

This thread is closed (or should be)
Started in Oct 2007, and the thread starter has not closed this thread.
Reputation Points: 69
Solved Threads: 75
Posting Pro in Training
JerryShaw is offline Offline
465 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: managing object in callback
Next Thread in C# Forum Timeline: Making a Single Instance Application Reappear





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC