我该如何在C#中使用代码来回答消息框

问题描述 投票:1回答:1

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

            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# vb.net winforms messagebox
1个回答
0
投票
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);
switch(click)
{
    case DialogResult.Yes:
        MessageBox.Show("Yes Clicked");
        break;
    case DialogResult.No:
        MessageBox.Show("No Clicked");
        break;
}
© www.soinside.com 2019 - 2024. All rights reserved.