Hi all,
I am creating an application for Library Management Systems.
I want to disable the close button initially and enable it once the user clicks on the menu item logoff.
Is there any way I could accomplish this functionality in my application?
I tried using the following code in the formClosing event but it is not woking out.
private void frmLibrary_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = false;
if (checkLogOff == false)
{
MessageBox.Show("Please Log Off before closing the Application");
e.Cancel = false;
this.ControlBox = false;
return;
}
else
{
this.ControlBox = true;
e.Cancel = true;
}
}
The value of checkLogOff Variable is set as follows:
public bool checkLogOff = false;
private void logOffToolStripMenuItem_Click(object sender, EventArgs e)
{
checkLogOff = true;
/*Code to update the logoff users in the database*/
}
When executing the application if I dont click on the LogOff menu item I am getting the dialog box but immediately after I press the OK Button in the Message Box the Application closes. But I dont want to allow the user to close the application before clicking on the LogOff MenuItem.
Please help me out in accomplishing this task.
Thanks in advance!