C# Taking Action by MessageBox OK Button

In C# Windows applications, below is a code example for action when pressing the OK button in the MessageBox alert box.


    var result = MessageBox.Show(@"Are You Sure?", @"Warning", 
                        MessageBoxButtons.OKCancel, 
                        MessageBoxIcon.Information);
             
  if (result.Equals(DialogResult.OK))
  {                   
        //Do Something
  } 

In our example, we first set the properties of our "MessageBox". Then we prepared our "if" block about what to do if the "OK" button is pressed.



You May Interest

C# Finding the Sine of an Angle

How to Find the Name of the Operating System in C# ?

C# Getting Current Time

Finding the Index Order of a Character in a String in C#

C# How To Find The Average Of 10 Numbers Using A While Loop