Add Buttons to a Form

Introduction

For example, let's see how to add a button to a form.
  1. Open the Toolbox:
    Add button 1
  2. Double-click Button to add it to the form
    Add button 2
  3. Change the Text property of the button
    Add button 3
  4. Change the Name property
    Add button 4
  5. Save your project as:
    Add button 5

Add functionality to the button

If you want to display a message when the button is clicked, a piece of code must be added to the button.
Double-click the button to display the code window. It shows the automatically generated code for the whole form application.
Add functionality

The following code will create a pop up window and display a message:
MessageBox.Show("Thanks for clicking the button!");
The completed code should look like
Add functionality
Click Save All.
Let's test the program by clicking Start to run the program!
Add functionality
Congratulations! Here is how it looks:

Add functionality

Create another button

Repeat the steps to add an exit button to the form. Use the following Button properties:

  1. Text: Exit the form
  2. Name: exitButton
  3. Code for the button: this.Close();
  4. Save All
  5. Run the program to see
    Add button 5


For more details, please contact me here.