c# ask question dialog code example
Example 1: c# yes or no dialog
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
}
else if (dialogResult == DialogResult.No)
{
}
Example 2: msgbox in c#
private void validateUserEntry()
{
if(serverName.Text.Length == 0)
{
string message = "You did not enter a server name. Cancel this operation?";
string caption = "Error Detected in Input";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result = MessageBox.Show(message, caption, buttons);
if (result == System.Windows.Forms.DialogResult.Yes)
{
this.Close();
}
}
}