How do I create a message box with “Yes”, “No” choices and a DialogResult?

前端 未结 11 1861
时光取名叫无心
时光取名叫无心 2020-11-28 00:40

I want to make simple Yes/No choiced MessageBox, but I think it is nonsense to design a form for that. I thought I could use MessageBox, add buttons, etc. to accomplish this

11条回答
  •  借酒劲吻你
    2020-11-28 01:12

    This should do it:

    DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
    if(dialogResult == DialogResult.Yes)
    {
        //do something
    }
    else if (dialogResult == DialogResult.No)
    {
        //do something else
    }
    

提交回复
热议问题