



Basics
Data Types Windows Forms Buttons Check Box Text Box Combo Box Radio Buttons Progress Bar Color & Font Dialogs Open & Save Dialogs Process Control
More Complex Examples
Audio Player Rotating Rectangle
|
Basics
with Visual Basic
Buttons
I am sure that on many applications you have seen buttons
displaying "Previous", "Next" and "Finish" on their forms. That is
exactly what buttons are for. To add a button to your form simply double
click on the button control in your toolbox, usually located on the left
side of your window. It looks something like this.

Figure 3: Toolbox
Now if you double click on the button
control it will create a button on your form and name it Button 1. To
open the properties dialog for the button control simply click once on
the desired button on your form. In the properties dialog you can then
change the text, name and other properties. In forms load event handler
you can also specify your button as the forms accept/cancel button.
AcceptButton: The button recognizes a click when ever the user presses
"Enter".
CancelButton: The button recognizes a click when ever the user presses
"Escape". Example:
Private Sub Form1_Load(ByVal
sender
As System.Object,
ByVal e As
System.EventArgs)
Handles MyBase.Load
Me.AcceptButton = Button1
End Sub
Now to give our button a function. Lets
use our button to change the Form.text from "Form1" to "My New Form".
First double click on your desired button on your form to go to the
click event handling for the chosen button. You should see something
like this:
Public Class Form1
Private Sub Form1_Load(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load
Me.AcceptButton = Button1
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Button1.Click
End Sub
End Class
Between the Private Sub Button1_Click and
the End Sub enter me.text = "My New Form". The
code should now look like this:
Public Class Form1
Private Sub Form1_Load(ByVal sender
As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load
Me.AcceptButton = Button1
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles Button1.Click
Me.Text = "My New
Form"
End Sub
End Class
Press the "Start debugging" button and
test your application.
If you liked this article then
Please Thumb This Up with a short review -

Continue to the Next Page.
Email us at: info@pro2visual.com
|
Popular Articles
Moving a borderless form in vb.net
ComboBox1.Items.Add
Link Progress Bar with
Timer in vb.net
How to
open a folder using the process control
Start Vb.net programming. No get
rich quick scam
How to Convert the Date
Format |