TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Donald C
1.5k
153
3.2k
Close application when frmLogin Cancel button is pressed
Oct 4 2016 3:03 AM
Hi Guys,
I'm having trouble with my application where despite calling Application.Exit(); it doesn't close
I've set up my frmLogin as a dialog screen with the cancel button set as a Dialog.CANCEL button.
In the frmMain constructor, I call a Security class, which in turn calls ShowLoginScreen.
if
(ShowLoginScreen(ProfileList, StartupClient.CompanyName, LastSessProf.UserName) ==
true
)
Application.Exit();
In the code snippet I've posted you can see the ShowLoginScreen being called.
In the ShowLoginScreen method, the frmLogin Screen is instantiated in a do while loop.
The Do while loop is there in case the wrong username or password is entered. (Is there a better way to do this?)
public
bool
ShowLoginScreen(List<
string
> ProfileList,
string
CompanyName,
string
UserName)
{
frmLogin frm =
new
frmLogin(ProfileList, CompanyName, UserName);
bool
bCloseApplication =
false
;
bool
bLoginResult =
false
;
do
{
var result = frm.ShowDialog();
if
(result == DialogResult.OK)
{
if
(ValidateLogin(frm.Profile, frm.UserName, frm.Password) ==
true
)
{
bLoginResult =
true
;
frm.Close();
}
else
{
bLoginResult =
false
;
MessageBox.Show(
"Incorrect Username or Password"
);
}
}
if
(result == DialogResult.Cancel)
{
bLoginResult =
true
;
frm.Close();
bCloseApplication =
true
;
return
bCloseApplication;
}
}
while
(bLoginResult ==
false
);
return
bCloseApplication;
}
If the user clicks Cancel, the DialogResult.Cancel response is generated and is dealt with by the if statement. I've tried Application.Exit() from there, but that didn't work.
The if statement checking for the cancel result works fine, and we leave the do... while loop, back to where the ShowLoginScreen was called. (1st Code snippet)
While debugging, the Application.Exit() code is stepped through, the method finishes and we head back to Program.cs where Application.Run(new frmMain()); is called.
How do I close the application when the frmLogin Cancel button has been pressed?
Any help would be appreciated,
Thanks.
Attachment:
Class1.zip
Reply
Answers (
7
)
importance of repository pattern
Script working as Keypress, Event in asp.net stop