c# message box code example

Example 1: c# error messagebox

MessageBox.Show("your message",
    "window title", 
    MessageBoxButtons.OK, 
    MessageBoxIcon.Warning // for Warning  
    //MessageBoxIcon.Error // for Error 
    //MessageBoxIcon.Information  // for Information
    //MessageBoxIcon.Question // for Question
   );

Example 2: c# MessageBox

MessageBox.Show("text", "title", MessageBoxButtons.OK, MessageBoxIcon.Warning);

Example 3: messagebox.show c# error

MessageBox.Show("Some text", "Some title", 
    MessageBoxButtons.OK, MessageBoxIcon.Error);

Example 4: winforms messagebox with button

string message = "Do you want to close this window?";  
string title = "Close Window";  
MessageBoxButtons buttons = MessageBoxButtons.YesNo;  
DialogResult result = MessageBox.Show(message, title, buttons);  
if (result == DialogResult.Yes) {  
    this.Close();  
} else {  
    // Do something  
}

Example 5: c# messagebox result

//MessageBox.Result
DialogResult result = MessageBox.Show("Do you like cats?", "Yes or No?", messageBoxButtons.YesNoCancel);

if (result == DialogResult.Yes)
    ;
else if (result == DialogResult.No)
    ;
else
    ;

Example 6: how to do a messagebox in c#

MessageBox.Show("Content", "Title", MessageBoxIcon.Error)