记事本应用程序关闭按钮 [英] Note pad application closeing button

查看:147
本文介绍了记事本应用程序关闭按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在记事本示例中,单击关闭"按钮,询问您是否要保存,不保存,不保存,取消options.how编写代码以显示这三个选项.

in Notepad example click to closeing button asked to do you want to save or not diasplay save,dontsave,cancel options.how to write code for displaying this three options

推荐答案

正如爱德华所说,这通常是从Form.Closing EventHandler完成的.正如他建议的那样,作为MessageBoxButtons.YesNo的替代方案,有MessageBoxButtons.YesNoCancel,然后您要做的就是适当地对消息进行措辞.

如果您需要更多想法,请在The Code Project上的 notepad 文本编辑器中搜索文章.有很多示例,看看它们如何处理此事件.特别要查找名为"dirty"或"isDirty"(或类似名称)的变量,这是它们跟踪文本是否已更改的方式.
As Eduard has said this is usually done from the Form.Closing EventHandler. As an alternative to MessageBoxButtons.YesNo as he suggests, there is MessageBoxButtons.YesNoCancel, and all you then have to do is word the message appropriately.

If you want more ideas, then search the articles here on The Code Project for either notepad or text editor. There are lots of examples, have a look at how they handle this event. In particular look for variables named ''dirty'' or ''isDirty'' (or something like that) which is how they keep track of whether the text has changed.


创建事件FormClosing事件的处理程序

事件参数包含一个Cancel属性

Create an event handler for the FormClosing event

The event argument contains a Cancel Property

private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
    if (MessageBox.Show("Are you sure you want to close the application?",
        "Close?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
    {
        e.Cancel = true;
    }
}



现在,您只需开发一个具有三个按钮的新表单,即可返回DialogResult.YesDialogResult.NoDialogResult.Cancel.

将上面的代码中的MessageBox.Show替换为调用您的自定义窗口的代码.



Now you only have to develop a new form with three buttons, that returns a DialogResult.Yes, DialogResult.No and a DialogResult.Cancel.

Replace the MessageBox.Show in the above code with code that calls your custom window.


这篇关于记事本应用程序关闭按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆