---
title: "Button Control in VB.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: "Pushpendra Singh"  
published: 2010-12-11  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/290/button-control-in-vb-dot-net  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# Button Control in VB.Net

Button class in [Windows](https://www.mindstick.com/articles/12793/insightful-review-of-stellar-phoenix-windows-data-recovery-home-edition) Forms represents a [Button control](https://www.mindstick.com/articles/391/button-control-in-c-sharp-dot-net). Whenever [button clicks](https://www.mindstick.com/forum/158690/how-can-you-handle-user-interactions-such-as-button-clicks-using-jquery), the Click [event handler](https://www.mindstick.com/forum/1371/c-sharp-dot-net-event-handler-delegate-question) is invoked. You can place code in the [Click event](https://www.mindstick.com/forum/424/how-to-call-form_paint-event-on-button-click-event) handler to perform any action you choose.\

[Drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) Button control from toolbox on windows form.

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/55de1076-e039-4a2e-aeb2-3e685113ba9b.png)

Drag and drop a TextBox change the name of Button

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/ae850b5e-732a-4042-8f22-83798e3c98f9.png)

## Code:

```
 Public Class Form3   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        'TextBox1 value will show in MessageBox        MessageBox.Show(TextBox1.Text) End Sub End Class
```

### Run the Project

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/eb567b68-b730-4b29-a531-a44165929fce.png)

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

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/a85ede6b-62af-4182-835b-c2fc502f3cea.png)

**Designating a [Button as](https://answers.mindstick.com/qa/32548/do-you-ever-use-the-favorite-button-as-a-bookmark-on-twitter) the Cancel Button.**

On Windows Form you can designate a Button control to be the cancel button. A cancel [button is clicked](https://answers.mindstick.com/qa/94813/why-does-my-app-terminate-when-the-button-is-clicked-on-android-studio) whenever the user presses the ESC key.

```
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load               'set button1 as cancell button        Me.CancelButton = Button1 End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Me.Close()'close window Form End Sub
```

**Output:**

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/dcae13d1-df54-472d-9a4c-b3584f6f338f.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 Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        'change backcolor of button        Button1.BackColor = Color.CadetBlue End Sub
```

At run time backcolor of button will be changed.

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/dcae13d1-df54-472d-9a4c-b3584f6f338f.png)

## ForeColor:

Through BackColor [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) we can change ForeColor of Button.

```
 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        ' change ForeColor of button text        Button1.ForeColor = Color.Red      End Sub
```

At run time Forecolor of button will be changed.

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/debfaf56-0724-44a2-8174-00c51fd52c86.png)

We can change both BackColor and ForeColor simultaneously.

```
 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        '' change BackColor of button tex        Button1.BackColor = Color.CadetBlue        ' change ForeColor of button text        Button1.ForeColor = Color.Red      End Sub
```

\

![Button Control in VB.Net](https://www.mindstick.com/mindstickarticle/3b6154b9-f2a3-42a3-8773-011530251e2f/images/1c4882ed-d361-4647-946f-3985f8332cb4.png)

---

Original Source: https://www.mindstick.com/articles/290/button-control-in-vb-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
