致力于开发C#应用程序。
我想在标题栏的右上角保持关闭按钮,但如果最终用户点击它,我想要的只是他得到的信息窗口,他不能关闭应用程序,直到其他一些正确的按钮。
有可能实现吗?
Tnx in adv!
答案 0 :(得分:4)
向表单的OnClosing
事件添加事件处理程序。 event参数包含元素Cancel
。将其设置为true
,它不会关闭。
基本上是这样的:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !stuffdone;
}
答案 1 :(得分:3)
您可以像这样处理FormClosing
事件处理程序
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
//there can be other reasons for form close make sure X button is clicked
// if close button clicked
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
}
}