In today's article I will show you a simple tutorial with example how you can display an error or warning message box in c#.net and vb.net, in windows application. Here we will over show error message, error icon and title with error description.
Error Message
C#.Net
private void btnShowMessage_Click(object sender, EventArgs e)
{
MessageBox.Show("This is sample error message box", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
VB.Net
Private Sub btnShowMessage_Click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("This is sample error message box", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Sub
In above code I have user MessageBox.Show() to show the error message box. Herer i haveused MessageBoxIcon.Error to display the error icon. Now let run the code to check the output.
C#.Net
private void btnShowMessage_Click(object sender, EventArgs e)
{
MessageBox.Show("This is sample error message box", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
VB.Net
Private Sub btnShowMessage_Click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("This is sample error message box", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Sub
In above code I have user MessageBox.Show() to show the error message box. Herer, I have used MessageBoxIcon.Warning to display the error icon. Now let run the code to check the output.