DialogResult result = MessageBox.Show("Do you wanna do something?", "Warning",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
if(result == DialogResult.Yes)
{
//code for Yes
}
else if(result == DialogResult.No)
{
//code for No
}
else if (result == DialogResult.Cancel)
{
//code for Cancel
}