C# 确认讯息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15036329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 13:51:16  来源:igfitidea点击:

Confirmation Message

c#winformsmessagebox

提问by user2085275

If a user checks the Checkbox, how do I code to show MessageBox.Show("...", with YesNoCancelbuttons in the message box, and when a user clicks no, another MessageBox.Showpops up?

如果用户选中 ,Checkbox我该如何编码以在消息框中显示MessageBox.Show("..."带有YesNoCancel按钮的 ,并且当用户单击“否”时,会MessageBox.Show弹出另一个?

My code is this so far and it will not work:

到目前为止,我的代码是这样的,它不起作用:

private void lipsCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        if (lipsCheckBox.Checked = MessageBox.Show("...?",
            "Want something else?",
            MessageBoxButtons.YesNoCancel, MessageBox.Show("...?",
            "Yea, Burt's bees?",
            MessageBoxButtons.YesNoCancel, MessageBox.Show("...??",
            "Hell yea LipxMedx?",
            MessageBoxButtons.YesNoCancel),
            MessageBoxIcon.Question);
    }

回答by saegeoff

Do something like this:

做这样的事情:

if (checkBox1.Checked)
{

     DialogResult dr = MessageBox.Show("Message.", "Title", MessageBoxButtons.YesNoCancel, 
        MessageBoxIcon.Information);

    if (dr == DialogResult.Yes)
    {
        // Do something
    }
}

You should be able to use this snippet to do the rest of what you need.

您应该能够使用此代码段来完成您需要的其余工作。

回答by Igoy

You can do it as follows:

你可以这样做:

private void lipsCheckBox_CheckedChanged(object sender, EventArgs e)
{
    if (lipsCheckBox.Checked)
    {     
        DialogResult dr = MessageBox.Show("...?", "Want something else?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

        if(dr == DialogResult.Yes)
        {
            //
        }
        else if(dr == DialogResult.Cancel)
        {
            //
        }
    }
}

回答by spajce

You must know about the MessageBox Dialog

你必须知道 MessageBox Dialog

if (checkBox1.Checked && (MessageBox.Show("Yes or no", "The Title", 
    MessageBoxButtons.YesNo, MessageBoxIcon.Question, 
    MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes))
{
    //TODO: Stuff
}