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

前端 未结 11 1887
时光取名叫无心
时光取名叫无心 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:05

    This simple code worked for me. I grabbed it from MSDN here:

    https://social.msdn.microsoft.com/Forums/en-US/d1092a96-96b0-4ca4-b716-0c8e55e42ee9/how-can-i-manage-messagebox-result-?forum=Vsexpressvcs

    if (System.Windows.Forms.MessageBox.Show
                ("Are you sure you want to add the audit?", "Add",
                System.Windows.Forms.MessageBoxButtons.YesNo, 
                System.Windows.Forms.MessageBoxIcon.Question)
                ==System.Windows.Forms.DialogResult.Yes)                
            // Do stuff after 'YES is clicked'
            else
            // DO stuff after 'NO is clicked'
    

提交回复
热议问题