C# MessageBox dialog result

前端 未结 5 1230
心在旅途
心在旅途 2021-01-30 04:17

I want to make a MessageBox confirmation. Here is the message box:

MessageBox.Show(\"Do you want to save changes?\", \"Confirmation\", messageBoxButtons.YesNoCan         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 04:26

    This answer was not working for me so I went on to MSDN. There I found that now the code should look like this:

    //var is of MessageBoxResult type
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);
    
    // If the no button was pressed ... 
    if (result == DialogResult.No)
    {
        ...
    }
    

    Hope it helps

提交回复
热议问题