MessageBox Buttons?

前端 未结 6 2063
太阳男子
太阳男子 2020-12-28 14:14

How would I say if the yes button on the messagebox was pressed do this,that and the other? In C#.

6条回答
  •  难免孤独
    2020-12-28 15:07

    1. Your call to MessageBox.Show needs to pass MessageBoxButtons.YesNo to get the Yes/No buttons instead of the OK button.

    2. Compare the result of that call (which will block execution until the dialog returns) to DialogResult.Yes....

    if (MessageBox.Show("Are you sure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
    {
        // user clicked yes
    }
    else
    {
        // user clicked no
    }
    

提交回复
热议问题