VB.Net - Button Control

VB.Net - Button Control

The Button control represents a standard Windows button. It is generally used to generate a Click event by providing a handler for the Click event.

Properties of the Button Control

The following are some of the commonly used properties of the Button control:
S.NPropertyDescription
1AutoSizeModeGets or sets the mode by which the Button automatically resizes itself.
2BackColorGets or sets the background color of the control.
3BackgroundImageGets or sets the background image displayed in the control.
4DialogResultGets or sets a value that is returned to the parent form when the button is clicked. This is used while creating dialog boxes.
5ForeColorGets or sets the foreground color of the control.
6ImageGets or sets the image that is displayed on a button control.
7LocationGets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
8TabIndexGets or sets the tab order of the control within its container.
9TextGets or sets the text associated with this control.











Events of the Button Control

The following are some of the commonly used events of the Button control:
S.NEventDescription
1ClickOccurs when the control is clicked.
2DoubleClickOccurs when the user double-clicks the Button control.
3GotFocusOccurs when the control receives focus.
4TabIndexChangedOccurs when the TabIndex property value changes.
5TextChangedOccurs when the Text property value changes.
6ValidatedOccurs when the control is finished validating.


EXAMPLE We will learn how to change the forecolor and back color using buttons and  Move a label or text using buttons in up, down left and right directions.

a. First of all create a label and name its text as "See the change here" and rename it to lbltxt( or any other you may feel easy)

b.Make 2buttons for changing back and fore color and name them respectively btnFore and btnBack.

c. Make four buttons for for moving up,down,left and right (btnUp, btnDown, btnRight, btnLeft)



Button


SEE THE CODE BELOW



Public Class Form1

    Private Sub btnFore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFore.Click
        lbl1.ForeColor = Color.Red
    End Sub

   
    Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        lbl1.BackColor = Color.Red

    End Sub

    Private Sub btnUp_down(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
        lbl1.Top += 10
    End Sub

    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
        lbl1.Top -= 10
    End Sub

    Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
        lbl1.Left -= 10
    End Sub

    Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
        lbl1.Left += 10
    End Sub
End Class
 Download the code here........
password  during extraction: soodeap

No comments:

Post a Comment