CIS206 - Advanced Visual Basic - Week 1

Introduction


Example 1 Source Code

Imports System
Module Week0101
    Sub Main()
        Console.WriteLine("Hello World")
    End Sub
End Module

        Compile using VBC Week0101.vb         


Example 2

 

Some Design Time Properties


' grpColor
Me.grpColor.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right)

Me.grpColor.Controls.AddRange(New System.Windows.Forms.Control() 
{
Me.Label3, Me.Label2, Me.Label1, Me.hsbBlue, Me.hsbGreen, Me.hsbRed})

Me.grpColor.Location = New System.Drawing.Point(8, 8)
Me.grpColor.Name = "grpColor"
Me.grpColor.Size = New System.Drawing.Size(352, 104)
Me.grpColor.TabIndex = 0
Me.grpColor.TabStop = False
Me
.grpColor.Text = "Color Control"

''hsbRed

Me.hsbRed.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right)

Me.hsbRed.Location = New System.Drawing.Point(96, 16)
Me.hsbRed.Maximum = 264
Me.hsbRed.Name = "hsbRed"
Me.hsbRed.Size = New System.Drawing.Size(240, 24)
Me.hsbRed.TabIndex = 0

'picPicture

Me.picPicture.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) Or System.Windows.Forms.AnchorStyles.Right)

Me.picPicture.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.picPicture.Location = New System.Drawing.Point(16, 184)
Me.picPicture.Name = "picPicture"
Me.picPicture.Size = New System.Drawing.Size(136, 120)
Me.picPicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.picPicture.TabIndex = 1
Me
.picPicture.TabStop = False

 

      

Event Handlers

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

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

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

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 Project


Example 3

 

Private Sub chkBold_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBold.CheckedChanged
    MessageBox.Show("CheckChanged fired")
    lblMessage.Font =
New Font(lblMessage.Font.Name, lblMessage.Font.Size, lblMessage.Font.Style Xor FontStyle.Bold)
End Sub

Private Sub chkItalic_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkItalic.CheckedChanged
    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
End Sub

 

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ToolTip.SetToolTip(
Me, "This is the form")
End Sub

Private Sub frmMain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    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()

End Sub

Private Sub frmMain_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
    MessageBox.Show("Message from frmMain_Closed")
End Sub

Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
   
MessageBox.Show("Message from OnClosed")
End Sub

Private Sub btnDefault_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDefault.Click
   
MessageBox.Show("This is the form's default action")
End Sub

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
   
Close()
End Sub

 

Download the Project    


Example 4

 


Download the Project


Assignment

        

 

Use the above User Interface as a model for this assignment. The program is to display Team Logos and Team Names in the Picture and Label controls. Then teams are selected using the Radio Buttons. The Label Font is controlled from within the Font Control Group Box. The Size control is a "Numeric Up Down Control" and is located in the VS Tool Box. The Exit Button terminates the program. Make sure you set initial values and edits and limits on what the user can select. Shortcut Keystrokes, Default / Cancel buttons, and Tab Order are important.

You have, I’m sure, noticed the Text Box in the middle of the Picture Box and the Button labeled Answer. The Answer Button is a toggle between the Picture Box and the Text Box. Clicking the button should toggle the display between the Picture Box and The Text Box. These controls should be the same size and occupy the same space. Clicking the button should also toggle the Button Text. Make sure when you change the button text that you don’t loose your shortcut key capability. The Text Box must be locked, so the contents cannot be changed.

The Text Box should contain an answer to this question:

Do the images displayed in the picture box have to be included with the .EXE when the program is complete. If Yes, then where in the project must they be stored. If No, where in the project are they stored?

If you don’t want to use Team Logos, you can use anything you would like. There is a graphics directory shipped with Visual Studio, or you can use images from any number of sources.

EMail the zipped project file to CIS206_Assignments@hotmail.com

Make the subject your name and assignment number (Last Name, First Name - Week 01)
No exceptions to this format.


Return to Home Page