Button Control in Windows Application C#

C# Button Control

In this c#.net tutorials we will learn how to use Button control in windows forms application.

The Button control is widely used to preform click event on windows form. Mostly we use button control for preform actions such as login, search, cancel, save and more. we can display a simple push button on windows forms by adding button control from toolbox. We will see more about button click events and properties of button in this c# tutorial.


Let’s understand about button control with an example in visual studio.

Button Control Example

Step 1 – Open Visual Studio –> Create a new Windows Forms Application.
Step 2 – Drag and drop Button control on windows form from Toolbox.
Step 3 –Set Text and ID properties of Button control.
Step 4 –For write serer side code (C#), go to Button control Click event.

meeraacademy.com
Button Control in Windows Application C#

 below list shows properties of Button control.

Properties Description
ID Identification name of button control.
Text It is used to display text in a control.
BackColor It is used to set background color of button control.
ForColor It is used to set text color of the control.
Image Set image path to display image on the control.
TabIndex It is used manage tab order of control.
Anchor It is describes an anchor position for the control when the form is resized.
Enable true/false – used to enable or disable control.
Visible true/false – It is used to hide or visible control on web page.
meeraacademy.com
Button Control in Windows Application C#.

Button control Events

There are many events of button control in c#, but we will understand about most important events in this post.

below list shows important events of Button control.

Events Description
Click Button Click event occurs when the button control is clicked.
MouseClick Event occurs when the button is clicked by the mouse.
MouseDown Event occurs when the mouse button is pressed over the button.
MouseEnter Event occurs when the mouse comes in the visible part of the button.
MouseHover Event occurs when the mouse comes over the button control.
MouseLeave Event occurs when the mouse leaves the visible part of the button control.
meeraacademy.com
Button Control Events in Windows Application

Button Click Event Example

Here we will take an example to understand button click event. The button click event is most used event of button control. For write server side code on button just double click on button control is the design view to create click event.

Button click event method will look like below code.

private void button1_Click(object sender, EventArgs e)
{
    // write server code here
}
meeraacademy.com
Button Control Events in Windows Application

We will learn rest of all button event in detail in later in c#.net post. Button Control Events


We hope that this c#.net tutorial helped you to understand about button control and it’s properties and events.


 

Leave a Reply

Your email address will not be published. Required fields are marked *