|
-
Jan 18th, 2007, 07:07 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Execute only when the form is closed.
hi guys! help please. I have 2 windows form, form1 and login form, and in form1 there is a button which when i click it the login form will appear, but right after the code that call login form there is a code that i want to be executed if only the login form is closed is this posible? What im trying to do here is to get Default Network Credential by using
Code:
System.Net.CredentialCache.DefaultCredentials;
if the user choose to use Defualt Network Credential or Show a Login dialog box which will ask for a Username,Password and domain if the user choose not to use the Default Network Credential and excecute the next line of code after the code which calls the login form. Please see the code below to give you more idea.Any help please. Thanks in advance!
Code:
public void chk_Credential_Settings()
{
if (chkSettingsUsedefault.Checked)
{
//Use default network credential. Should be logged on to domain.
listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
listService.PreAuthenticate = true;
}
else
{
if (DomainUserName != null && DomainPswrd != null && DomainName != null)
{
//MessageBox.Show("DEFINED");
//Call the LogIn Form
//execute the code below only when the LogIn form is close
//The DomainUserName, DomainPswrd, DomainName is the
//returned value when the form is closed.
listService.Credentials = new NetworkCredential(DomainUserName, DomainPswrd, DomainName);
listService.PreAuthenticate = true;
}
else
{
}
}
}
-
Jan 18th, 2007, 07:33 PM
#2
Re: Execute only when the form is closed.
Display the login form by calling its ShowDialog method, which I would think you'd be doing anyway. ShowDialog blocks until the form is dismissed.
-
Jan 18th, 2007, 08:26 PM
#3
Thread Starter
Fanatic Member
Re: Execute only when the form is closed.
-
Jan 18th, 2007, 08:37 PM
#4
Re: Execute only when the form is closed.
Note also that dismissing a dialogue does not dispose it, so you should create the form with a using statement:
Code:
using (LoginForm dialogue = new LoginForm())
{
if (dialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
'Do something here.
}
}
-
Jan 18th, 2007, 09:34 PM
#5
Thread Starter
Fanatic Member
Re: Execute only when the form is closed.
Thanks for that usefull info.
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
|