---
title: "Button Control in C#.Net"  
description: "Button class in Windows Forms represents a Button control. Whenever button clicks, the Click event handler is invoked. You can place code in the Click"  
author: "Anonymous User"  
published: 2011-01-24  
updated: 2020-01-21  
canonical: https://www.mindstick.com/articles/391/button-control-in-c-sharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Button Control in C#.Net

A button is a control, which is an interactive component that enables users to communicate with an application. The Button class inherits directly from the ButtonBase class. A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus.\

How to use Button Control\

Drag and drop Button and TextBox control from toolbox on windows form.

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/563c941f-52ca-4936-8d54-04268fd20312.png)

Drag and drop a TextBox and label as Enter Name .

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/6436f850-8d6f-4523-9ba0-58ac1a70a0cd.png)

Write code on Button click

```
private void btnSubmit_Click(object sender, EventArgs e)         {           //MessageBox will show the text entered in textbox            MessageBox.Show("Entered name is "+textBox1.Text);        }
```

##### Run The Project:

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/61a8fe50-f2f8-46e4-ba28-78643192cf0f.png)

When you insert any text and click submit button then inserted text will show in the Message box.

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/93f1b0cd-3efd-4744-a5b5-b371c2bf0437.png)

##### Set a Button as the Cancel Button.

On Windows Form you can designate a Button control to be the cancel button. A cancel button is clicked whenever the user presses the ESC key.

```
private void btnSubmit_Click(object sender, EventArgs e){                this.Close(); //close window Form}private void Form2_Load(object sender, EventArgs e){          // Set button as cancel button        this.CancelButton = btnSubmit;}
```

\

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/82a955e1-6197-4160-8ad2-e8965e809644.png)

When you press Esc key on the keyboard then Window Form will closed.

##### Properties of Button:

##### BackColor

Through BackColor properties we can change BackColor of Button.

```
private void Form2_Load(object sender, EventArgs e){  //change button backcolor          btnSubmit.BackColor = Color.CadetBlue;}
```

##### Output:

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/8840c044-abff-448d-990c-0cebf2cba423.png)

At run time backcolor of button will be change.

##### ForeColor:

```
private void Form2_Load(object sender, EventArgs e){        //change forecolor of button text        btnSubmit.ForeColor = Color.Red;}
```

At run time ForeColor of button will be change.

##### Output:

![Button Control in C#.Net](https://www.mindstick.com/mindstickarticle/1dcccd6c-ccbd-4d4f-acfd-578fd773fb31/images/0459a90b-ec47-444c-9ba4-313361abfd71.png)

---

Original Source: https://www.mindstick.com/articles/391/button-control-in-c-sharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
