Click here to Skip to main content
16,006,749 members
Home / Discussions / C#
   

C#

 
GeneralRe: Form.Close() Pin
Salil Khedkar20-Sep-04 2:10
Salil Khedkar20-Sep-04 2:10 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 3:15
exhaulted20-Sep-04 3:15 
GeneralRe: Form.Close() Pin
Heath Stewart20-Sep-04 6:55
protectorHeath Stewart20-Sep-04 6:55 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 22:22
exhaulted20-Sep-04 22:22 
GeneralRe: Form.Close() Pin
Salil Khedkar20-Sep-04 23:30
Salil Khedkar20-Sep-04 23:30 
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 4:11
exhaulted21-Sep-04 4:11 
GeneralRe: Form.Close() Pin
Heath Stewart21-Sep-04 5:28
protectorHeath Stewart21-Sep-04 5:28 
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 6:23
exhaulted21-Sep-04 6:23 
Heath, just to check i've got things right and we are both going along the same lines of thought.

I have a bool called closing in the form instance.

My forms constructor
public Form1()
{
InitializeComponent();
closing = false;
SystemEvents.SessionEnding += new SessionEndingEventHandler(OnSessionEnding);
}


Form1_Closing
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//Write the details
SaveSchedules();

//Check the state variable
if (!(closing))
{
//Check for the password
if (!(CheckPassword()))
e.Cancel = true;
}
}

OnSessionEnding
private void OnSessionEnding(object sender, SessionEndingEventArgs e)
{
//Save the schedules
SaveSchedules();

//Set the state variable
closing = true;
}


Thats it, all the relevant code as far as i'm aware.
If the user closes the form manually then i want checkpassword to be called.
This works OK.
If the user enters the correct password, CheckPassword returns true and
e.Cancel remains false, the application exits nicely.

If the user logs off of the machine or shuts it down i don't want checkpassword to be called. To accomplish this, as i was advised in the previous posts i am using the state variable closing.
The closing variable is set to true in the OnSessionEnding method.

This is what i believe has been suggested but the CheckPassword function is still called. If i've misunderstood whats been said in the previous posts then please let me know so i can make the relevant changes.

Thanks for all your help and patience

Kev
GeneralRe: Form.Close() Pin
Heath Stewart21-Sep-04 6:37
protectorHeath Stewart21-Sep-04 6:37 
GeneralRe: Form.Close() Pin
exhaulted21-Sep-04 22:44
exhaulted21-Sep-04 22:44 
GeneralRe: Form.Close() Pin
Heath Stewart22-Sep-04 6:57
protectorHeath Stewart22-Sep-04 6:57 
GeneralRe: Form.Close() Pin
yoaz20-Sep-04 2:56
yoaz20-Sep-04 2:56 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 3:10
exhaulted20-Sep-04 3:10 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 4:50
Nicholas Cardi20-Sep-04 4:50 
GeneralRe: Form.Close() Pin
exhaulted20-Sep-04 6:16
exhaulted20-Sep-04 6:16 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 7:59
Nicholas Cardi20-Sep-04 7:59 
GeneralRe: Form.Close() Pin
Nicholas Cardi20-Sep-04 8:07
Nicholas Cardi20-Sep-04 8:07 
GeneralData Table From DataRow[] Pin
sreejith ss nair19-Sep-04 22:50
sreejith ss nair19-Sep-04 22:50 
GeneralRe: Data Table From DataRow[] Pin
Sendilkumar.M20-Sep-04 1:52
Sendilkumar.M20-Sep-04 1:52 
GeneralRe: Data Table From DataRow[] Pin
sreejith ss nair20-Sep-04 17:35
sreejith ss nair20-Sep-04 17:35 
GeneralRe: Data Table From DataRow[] Pin
Sendilkumar.M20-Sep-04 18:27
Sendilkumar.M20-Sep-04 18:27 
Generalmultiple selection in datagrid Pin
Sudee19-Sep-04 19:47
Sudee19-Sep-04 19:47 
GeneralRe: multiple selection in datagrid Pin
sreejith ss nair19-Sep-04 20:27
sreejith ss nair19-Sep-04 20:27 
GeneralRe: multiple selection in datagrid Pin
Sudee19-Sep-04 21:15
Sudee19-Sep-04 21:15 
GeneralRe: multiple selection in datagrid Pin
sreejith ss nair19-Sep-04 21:35
sreejith ss nair19-Sep-04 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.