Adding a Button Control in Windows Form

Submitted by: 

In creating Visual Basic.Net application, one of the most common control used is a Button. Using Visual Basic, it is important to use a button control, because Button is used to initiate actions, usually by clicking on it. Using visual Basic.Net, there are many ways on how to add a button tool to a form. In our case, we’re not going to double click the button tool in the toolbox to add the control to the form. But instead, with your Form displayed in Visual Basic Design Environment, follow the steps:

1.On the Toolbox, choose the button tool and using your mouse left click, click once.
2.Then press the left click and drag your mouse to a control form, and release it.
3.Next, as you can observe the mouse pointer will turn into a cross
4.Press and hold down the left mouse button
5.Drag across the form with the button held down
6.Then, let go of the mouse button when you're satisfied with the size
7.And finally, a Button is drawn

The steps above can be used to draw most of the controls onto the form such as: labels, textboxes, combobox, etc.

Same with the other controls, Button control has a list of properties,two of these properties is a Name property and a Text property. Currently the default settings of our button control are set to “Button1” both Name and Text property. You can modify it to anything you like and you can do this by following these steps:
1.Click the button to highlight it.
2.Then using the property box change the Text property to “Compute”
3. And “btncompute” for the Name property.
4.Add a label, change the Name property to “lblans”
5.Same with the Text property as “Answer”.
Your form should now look something like this:


And double click the button and add the following code:

  1. Private Sub bntcompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntcompute.Click
  2. lblans.Text = 7 + 8
  3. End Sub

Then you can test your program by pressing “F5”.

When the user click the button, the “Answer” label will change into “15”, because 7 plus 8 is equal to 15 and result value has been assigned to the text property of the label.


Comments

it's nice this source code . guys please. help me to make my high school students information system. thanks

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.