如何显示带有复选框的 MessageBox? [英] How to show a MessageBox with a checkbox?

查看:17
本文介绍了如何显示带有复选框的 MessageBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 MessageBox,它有 Yes/No 按钮和一个复选框.

I would like to create a MessageBox that has Yes/No buttons AND a checkbox.

该应用程序是一个图片调整器,它将一次调整多张图片的大小;在此过程中,它将检查新位置文件名是否存在,并提供覆盖它的选项.

The application is a picture resizer and it will be re-sizing a number of pictures at once; in the process it will check if the new location filename exists with the option to overwrite it.

MessageBox 将允许用户根据需要覆盖任何新文件,而复选框将防止必须单击 Yes x如果他们想覆盖每个文件的次数.

The MessageBox will give the user the option to overwrite any new files if desired, while the checkbox will prevent having to click Yes x number of times if they want to overwrite every file.

如何向 MessageBox 对话框添加复选框?

How do I add a checkbox to a MessageBox dialog?

推荐答案

您不能向 MessageBox 添加复选框.正如 Tim 和 rsbarro 所建议的,您应该创建一个自定义对话框.蒂姆的答案会很有效,并且不需要创建新类.如果你想在设计器中设计表单,你可以试试这个.

You can't add a checkbox to a MessageBox. As Tim and rsbarro suggest, you should create a custom dialog. Tim's answer will work well, and doesn't require creation of a new class. If you want to design the form in the designer though, you could try this.

  • 使用您需要的两个按钮和复选框创建一个新表单.
  • 在表单设计器中,将Yes按钮的DialogResult属性设置为Yes,将No按钮的DialogResult属性设置为No.这将让您发现用户单击了哪个按钮.
  • 在表单上创建一个反映复选框状态的属性(可选 - 我不喜欢从另一个表单引用一个表单上的控件,但如果您将复选框设为公开,那也可以).
  • Create a new form with the two buttons and the checkbox you'll need.
  • In the forms designer, set the DialogResult property of the Yes button to Yes, and that of the No button to No. This'll let you discover what button the user clicked.
  • Create a property on the form that reflects the state of the checkbox (optional - I don't like to reference a control on one form from another form, but if you make the checkbox public, that'll work too).
public bool DoForAll
{
    get { return checkBox.Checked; }
}

  • 在您的主表单上,根据需要显示子表单.例如:
  • var options = new Options();
    var result = options.ShowDialog();
    if (result == DialogResult.Yes)
    {
        var doForAll = options.DoForAll;
    }
    

    这篇关于如何显示带有复选框的 MessageBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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