首页 > 解决方案 > 如何以编程方式单击 MessageBox 上的按钮

问题描述

我检查时有一个单选按钮,它应该给出一条消息

DialogResult click = MessageBox.Show("Would you like to convert the actual values to US Customary ?\n Clicking No changes just the unit system.", "Change Unit Systems to US Customary", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

if (click == DialogResult.Yes)
{
    //some code 
}

如何从按钮中的内部代码回答此消息是否?

标签: c#winformsmessagebox

解决方案


我不希望出现消息

如果您真的不想要它,那么只需在该单选按钮的检查更改时执行您的操作。

private void radioButton1_CheckedChanged(Object sender, EventArgs e)
{
   //Validate to make sore it was not just deselected
   if (radioButton1.Checked)
   {
     //Do whatever I want when the use checks this radio button
   {
}

推荐阅读