Disable the Close Button until the user clicks on the LogOff MenuItem
<p>I am creating an application for Library Management Systems.</p>

<p>I want to disable the close button initially and enable it once the user clicks on the menu 
item logoff.</p>

<p>Is there any way I could accomplish this functionality in my application?</p>

<p>I tried using the following code in the formClosing event but it is not working out.</p>

<pre><code>  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;

  }

  }
</code></pre>

<p>The value of checkLogOff Variable is set as follows:</p>

<pre><code>  public bool checkLogOff = false;

  private void logOffToolStripMenuItem_Click(object sender, EventArgs e)

  {

  checkLogOff = true;

  /*Code to update the logoff users in the database*/

  }
</code></pre>

<p>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.</p>

<p>Please help me out in accomplishing this task.</p>

<p>Thanks in advance! </p>
