MessageBox.Show():
MessageBox is a class and Show is a function that displays a message in a small window in the center of the Form.
MessageBox is used to provide confirmations of a task being done or to provide warnings before a task is done.
Example
Figure 1 Windows Form
Figure 2 Code Snippet
OUTPUT
Figure 3 Showing the output
Note
By default the OK Button will be shown.
Figure 4 Second and third argument MessageBoxIcon
Figure 5 Fourth argument specifies MessageBoxIcon
Dialog Result
DialogResult is an enumeration of the possible return values of a dialog box including a MessageBox.
Figure 6 Design phase
Form1.cs
- private void button1_Click(object sender, EventArgs e)
- {
- DialogResult d;
- d=MessageBox.Show("Welcome to C# Corner","Learn C#",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
- if(d==DialogResult.Yes)
- {
- Close();
- }
- }
OUTPUT
Figure 7 Final output
Thank you.