| | |
Open and Close Winform
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
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.
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.
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
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.
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.
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.
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
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
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.
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
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 ...
Let the Main form continue if the DialogResult is Ok, otherwise Close the main application.
--Jerry
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Solved Threads: 0
C# Syntax (Toggle Plain Text)
this.Hide(); //hide login form Form1 mainForm = new Form1; mainForm.ShowDialog(); //important to use ShowDialog(); so that this.Close(); //login form closes only when mainForm closes.
![]() |
Similar Threads
- manually open and close ports (Windows NT / 2000 / XP)
- Need help with a program to open and close disk drive. (C)
- Presario 700 screen will not stay open (Monitors, Displays and Video Cards)
- Re: manually open and close ports (Windows NT / 2000 / XP)
- To open and close in turn all the files in a directory (C++)
- ofstream - detect if file has been deleted between open and close (C++)
Other Threads in the C# Forum
- Previous Thread: managing object in callback
- Next Thread: Making a Single Instance Application Reappear
| Thread Tools | Search this Thread |
.net access ado.net algorithm array backup barchart bitmap box broadcast buttons c# check checkbox client combobox control conversion csharp custom database databasesearch datagrid datagridview datagridviewcheckbox dataset datetime degrees development draganddrop drawing dynamiccreation encryption enum equation event excel file form format formatting forms function gdi+ httpwebrequest image index input install interface java label list listbox mandelbrot math mouse mouseclick mysql namevaluepairs operator path photoshop picturebox pixelinversion post powerpacks programming property radians regex remote remoting resource restore richtextbox server sleep socket sql statistics stream string table text textbox thread time timer update usercontrol validation visualstudio wait webbrowser windows winforms working wpf xml






