【发布时间】:2010-11-30 17:18:29
【问题描述】:
我正在为图书馆管理系统创建一个应用程序。
我想最初禁用关闭按钮,并在用户单击菜单后启用它 项目注销。
有什么方法可以在我的应用程序中实现此功能?
我尝试在 formClosing 事件中使用以下代码,但没有成功。
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;
}
}
checkLogOff 变量的值设置如下:
public bool checkLogOff = false;
private void logOffToolStripMenuItem_Click(object sender, EventArgs e)
{
checkLogOff = true;
/*Code to update the logoff users in the database*/
}
在执行应用程序时,如果我不单击 LogOff 菜单项,则会出现对话框,但在按下消息框中的 OK 按钮后,应用程序会立即关闭。但我不想让用户在单击 LogOff MenuItem 之前关闭应用程序。
请帮助我完成这项任务。
提前致谢!
【问题讨论】:
-
嗯,为什么不在人们关闭表单时将其注销?还是不够难?
标签: c#