CIS205 - Visual Basic - Week 2

VB Controls

 


Example 1


Design View








Run Time

 

    Setting the initial values trigger the ValueChanged event

Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    hsbRed.Value = 255
    hsbGreen.Value = 0
' If the value already is 0
    hsbBlue.Value = 0 ' the ValueChanged does NOT fire

End Sub

    When the ValueChanged event fires, update the form's background color and display the color value

Private Sub hsbGreen_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles hsbGreen.ValueChanged
    Me.BackColor = Color.FromArgb(hsbRed.Value, hsbGreen.Value, hsbBlue.Value)
    lblG.Text = Format(hsbGreen.Value, "##0")

End Sub

    Change the Image property value from the appropriate hidden picture control

Private Sub optMouse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles optMouse.Click
   
picPicture.Image = picMouse.Image

End Sub

    Set the Visible property of the Group control to display or hide all of the group's contents

Private Sub chkNumbers_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNumbers.CheckedChanged
   
grpNumbers.Visible = chkNumbers.CheckState

End Sub

 

Download the example


Example 2

 


    Using the Anchor and Dock properties

    Toggling the Timer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Beep()
        Beep()

End Sub

Private Sub btnToggle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToggle.Click
        Timer1.Enabled = Not Timer1.Enabled

End Sub

 

Download the example


Example 3

 

    Setting Font Properties

Dim myStyle As New FontStyle()

myStyle = lblMessage.Font.Style
myStyle = IIf(chkItalic.CheckState = CheckState.Checked, myStyle Or FontStyle.Italic, myStyle And Not FontStyle.Italic)

Dim myFont As New Font(lblMessage.Font, myStyle)
lblMessage.Font = myFont

 

    Setting up Tool Tips

Dim myToolTip As New ToolTip()

myToolTip.SetToolTip(lblMessage, "This is a label")
myToolTip.SetToolTip(chkBold, "Check to set the label to Bold")
myToolTip.SetToolTip(chkItalic, "Check to set the label to Italic")
myToolTip.SetToolTip(chkUnderline, "Check to set the label to Underline")
myToolTip.SetToolTip(btnDefault, "Click or Press <Enter>")
myToolTip.SetToolTip(btnExit, "Click or Press <ESC>")

chkBold.Focus()
chkBold.Show()

 

Download the example


Assignment
        Problem 2.2    Flag Viewer


 

Return to Home Page