In this article I will explain with an example, how to display MessageBox in Windows Forms (WinForms) Application using C# and VB.Net.
Form Design
The Form consists of following control:
Label – For labeling TextBoxes.
TextBox – For capturing user input.
Button – For displaying MessageBox.
The Button has been assigned with following event handler:
Events
Click – Submits the Form when Button is clicked.
Displaying MessageBox in C# and VB.Net
When the Submit Button is clicked, a message is displayed using the Show method of MessageBox class.
C#
private void OnSubmit(object sender, EventArgse)
{
MessageBox.Show("Your details have been saved successfully.");
}
VB.Net
Private Sub OnSubmit(sender As Object, e As EventArgs) Handles btnSubmit.Click
MessageBox.Show("Your details have been saved successfully.")
End Sub
Screenshot
Downloads