Hello, S2009.
Beforehand little quotation from msdn:
CancelEventArgs..::.Cancel Property
Gets or sets a value indicating whether the event should be canceled.
Property Value
Type: System..::.Boolean
true if the event should be canceled; otherwise, false.
And now let's look at your code:
private void frmLibrary_FormClosing(object sender, FormClosingEventArgs e)
{
// there's no need in this line, because it's set to false by default
e.Cancel = false;
if (checkLogOff == false)
{
MessageBox.Show("Please Log Off before closing the Application");
// regarding to quote from msdn, you say: "Everything ok, keep closing"
e.Cancel = false;
// I'll talk about this one later.
this.ControlBox = false;
// unnecessary thing, because your method already finished it's job
return;
}
else
{
// Later ..
this.ControlBox = true;
// regarding to quote from msdn, you say: "Something goes wrong. Stop closing form"
e.Cancel = true;
}
}
Ok, now few words about ControlBox. I suppose it would be more understandable for user if you will show/hide ControlBox in some other place. E.g. make it hidden when loading form and show it while logging off.
Also just a few thoughts in loud. I don't know if that's suited for your situation, but maybe you could ask user if he wants to log off and sign him off if he wants also and in formClosing event (insdead of showing/hiding ControlBox).