如何显示一个复选框一个消息? [英] How to show a MessageBox with a checkbox?

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

问题描述

我想创建一个的MessageBox 有<大骨节病>是 / <大骨节病>否按钮和一个复选框。



应用程序是一个图像大小调整,这将是重新调整大小一批一次的图片;在这个过程中它会检查是否新的位置文件名以覆盖它的选项存在。



的MessageBox 将给用户覆盖如果需要任何新文件的选项,而复选框可以防止不必点击<大骨节病>是 X 的,如果他们要覆盖每个文件次数。



我如何添加一个复选框,一个的MessageBox 对话框?


解决方案

您不能复选框添加到一个消息框。蒂姆和rsbarro建议,应创建一个自定义对话框。蒂姆的答案将工作做好,并且不需要一类新的创造。如果你想,虽然设计在设计表格,你可以试试这个。




  • 创建的两个按钮和复选框的新形式你所需要的。

  • 在窗体设计器中,<大骨节病>是按钮的的DialogResult 属性设置为是的,这的<大骨节病>否按钮号这会让你发现用户点击了哪个按钮。

  • 创建窗体上的属性,反映了复选框的状态(可选 - 我不喜欢从其他形式的一种形式在参一控,但如果你的复选框公开,这会工作太)。



<预类=郎CSHARP prettyprint-覆盖> 公共BOOL DoForAll
{
{返回checkBox.Checked; }
}




  • 在您的主要形式,展现了孩子在需要的时候形成。例如:



<预类=郎CSHARP prettyprint-覆盖> VAR选项=新的选项();
VAR的结果= options.ShowDialog();
如果(结果== DialogResult.Yes)
{
VAR doForAll = options.DoForAll;
}


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.

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.

How do I add a checkbox to a MessageBox dialog?

解决方案

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.

  • 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; }
}

  • On your main form, show the child form when needed. For instance:

var options = new Options();
var result = options.ShowDialog();
if (result == DialogResult.Yes)
{
    var doForAll = options.DoForAll;
}

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

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