Thursday, December 15, 2011

Allowing only LETTERS in a textbox

Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress

If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 AndAlso Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 122 Then

MessageBox.Show("Only Letters")

e.Handled = True

ElseIf Asc(e.KeyChar) = 8 Then
e.Handled = False

End If
End Sub

Allow only LETTERS and Backspace in a textbox

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress

If (e.KeyChar >= "a" And e.KeyChar = "A" And e.KeyChar
e.Handled = False

Else
e.Handled = True
MessageBox.Show("Only Letters")

End If
End Sub

Allow NUMBERS, BACKSPACE and a DOT in a textbox

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress

'There are a couple scenerios this code is looking for. One is checking for the Decimal period "."
'and whether it exists in the textbox already. The other is seeing if the keypress was a Number and
'Control based key.


If e.KeyChar = "." Then


'If a value higher than -1 is returned, it means there IS a existing decimal point’


If TextBox1.Text.IndexOf(".") > -1 Then

'This says that I already dealt with the _KeyPress event so do not do anything else with this event.


e.Handled = True

End If

'Remember you want numbers to get through and the Control keys like “Backspace”

ElseIf Char.IsNumber(e.KeyChar) = False AndAlso Char.IsControl(e.KeyChar) = False Then

'This says that I already dealt with the _KeyPress event so do not do anything else with this event.

e.Handled = True

End If
End Sub

Date and Time Difference user interface:








here is the CODE:

Public Class frmDateandTimeDifference

Private Sub btnGettheDifference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGettheDifference.Click

Dim Diff1, Diff2, Diff3 As Long

Select Case cboSelect.SelectedIndex

Case 0
Diff1 = DateDiff(DateInterval.Year, dtpStartDate.Value, dtpEndDate.Value)
Diff2 = DateDiff(DateInterval.Month, dtpStartDate.Value, dtpEndDate.Value)
Diff3 = DateDiff(DateInterval.Day, dtpStartDate.Value, dtpEndDate.Value)
lblOutput.Text = Diff1 & " Year/s " & Diff2 & " Month/s " & Diff3 & " Day/s "

Case 1
Diff1 = DateDiff(DateInterval.Hour, dtpStartTime.Value, dtpEndTime.Value)
Diff2 = DateDiff(DateInterval.Minute, dtpStartTime.Value, dtpEndTime.Value)
Diff3 = DateDiff(DateInterval.Second, dtpStartTime.Value, dtpEndTime.Value)
lblOutput.Text = Diff1 & " Hour/s " & Diff2 & " Minute/s " & Diff3 & " Second /s "

End Select
End Sub

Private Sub frmDateandTimeDifference_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

cboSelect.Items.Add("Year, Month, Day")
cboSelect.Items.Add("Hour, Minute, Second")
End Sub

Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

Me.Close()
End Sub

End Class

**Run and Save the program.....

Proper Case

1. Proper Case user interface:



2. Code....

Public Class frmProperCase

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

txtProperCase.Text = Microsoft.VisualBasic.StrConv(txtInput.Text, VbStrConv.ProperCase)
End Sub

Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

Me.Close()
End Sub

End Class

3. Save and RUN the program...

Character Count

1. Character Count user interface:



2. The Code....

Public Class frmCharacterCount

Private Sub btnClickHereToCount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClickHereToCount.Click

Dim length, x, count As Integer
Dim letter As String

length = Microsoft.VisualBasic.Len(txtPhrase.Text)

For x = 1 To length

letter = Microsoft.VisualBasic.Mid(txtPhrase.Text, x, 1)

If Microsoft.VisualBasic.StrComp(letter, txtcharacter.Text, CompareMethod.Text) = 0 Then

count = count + 1
End If

Next

lblOutput.Text = "There are " & count & " " & txtcharacter.Text & " in the Phrase."
End Sub

Private Sub exit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exit.Click

Me.Close()
End Sub
End Class

3. Save and RUN the program...

Button Play

1.A program that will initially display two buttons, the first is enabled and the other is disabled. The behavior will be, once you click the Enabled button, it will be disabled, while the other button (which is disabled) will be enabled.



2. CODE:


Public Class frmButtonPlay

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

btn1.Enabled = False
btn2.Enabled = True
End Sub


Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

btn2.Enabled = False
btn1.Enabled = True
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()
End Sub

Private Sub frm2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

btn1.Enabled = True
btn2.Enabled = False
End Sub

End Class

3. Save & Run...

Got Focus

1. A program that will illustrate the GotFocus event with four text box and a label. As you move the focus from one text box to another, the label will tell you which of them has the focus.



2. The CODE:


Public Class frm3

Private Sub GotFocus_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub MultipleEvents(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, TextBox4.Enter

ShowInfo.Text = "Text " & Microsoft.VisualBasic.Right(ActiveControl.Name, 1) & " is in Focus"
End Sub

Private Sub Label1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Leave
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

Me.Close()
End Sub

End Class

3. Save & Run your program.

Visible Enabled

1. Make an interface like this ti notice the trick.



2. The code..

Public Class frm2

Private Sub VisibleEnabled_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

TextBox.Visible = False
End Sub

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click

TextBox.Visible = True
TextBox.Text = "I am here."
TextBox.Enabled = True
End Sub

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click

TextBox.Visible = True
TextBox.Text = "I am enabled."
TextBox.Enabled = True
End Sub

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click

TextBox.Enabled = False
TextBox.Text = "I am disabled."
End Sub

Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox.TextChanged
End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()
End Sub

End Class

3. Save & Run the program.

Mouse Locator

1. A program showing the location of the pointer (x and y) in the title bar. Form name is "frm1".





2. Enter the CODE:


Public Class frm1

Private Sub MouseLocator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub MouseLocator_Mousemove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

Me.Text = "Your location in X is " & e.X & " and Y is " & e.Y

End Sub

Private Sub backtoindex_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles backtoindex.Click

Me.Close()

End Sub
End Class

3. Save and Run your program.

Grade Generator

1. Construct the user interface as follows:



2. Code:


Public Class frmGradeGenerator

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim FinalGrade As Single

FinalGrade = Val(txtPrelimGrade.Text) * 0.3 + Val(txtMidtermGrade.Text) * 0.3 + Val(txtFinalsGrade.Text) * 0.4

txtFinalGrade.Text = FinalGrade

Select Case FinalGrade

Case 98 To 100
txtEquivalentGrade.Text = "1.0"
txtRemarks.Text = "Excellent"

Case 95 To 97
txtEquivalentGrade.Text = "1.25"
txtRemarks.Text = "Outstanding"

Case 92 To 94
txtEquivalentGrade.Text = "1.5"
txtRemarks.Text = "Very Good Work"

Case 89 To 91
txtEquivalentGrade.Text = "1.75"
txtRemarks.Text = "Very Satisfactory work"

Case 86 To 88
txtEquivalentGrade.Text = "2.0"
txtRemarks.Text = "Quite Good Work"

Case 83 To 85
txtEquivalentGrade.Text = "2.25"
txtRemarks.Text = "Good Work"

Case 80 To 82
txtEquivalentGrade.Text = "2.5"
txtRemarks.Text = "Satisfactory Work"

Case 77 To 79
txtEquivalentGrade.Text = "2.75"
txtRemarks.Text = "Moderately Satisfactory Work"

Case 75 To 76
txtEquivalentGrade.Text = "3.0"
txtRemarks.Text = "Passing"

Case Is < 75
txtEquivalentGrade.Text = "5.0"
txtRemarks.Text = "Failure"

Case Else
MsgBox("You Enter an Invalid Grade", MsgBoxStyle.Exclamation, "Warning")

End Select
End Sub

End Class

3. Save and Run the program.

Case Conversion

1. Construct the user interface:



2. Enter the code as follows:


Public Class frmCaseConversion

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

txtLcase.Text = Microsoft.VisualBasic.LCase(txtInput.Text)
txtUcase.Text = Microsoft.VisualBasic.UCase(txtInput.Text)
txtPcase.Text = Microsoft.VisualBasic.StrConv(txtInput.Text, VbStrConv.ProperCase)
End Sub

End Class

3. Save and Run..

Palindrome Test

1. Design the following:



2. Enter the code as follows:


Public Class frmPalindromeTest

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click

Dim Result As String

txtReverse.Text = Microsoft.VisualBasic.StrReverse(txtInput.Text)

Result = Microsoft.VisualBasic.StrComp(txtInput.Text, txtReverse.Text)

If Result = 0 Then

lblResult.Text = "The string is a Palindrome"

Else
lblResult.Text = "The string is not a Palindrome"

End If
End Sub

End Class

3. Save and Run the program.

Toss Coin / Dice Roll

1. Design the interface as follows:



2. Enter the Code.


Public Class frmCoinDice

Private Sub btnToss_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnToss.Click

Dim Toss As Integer

Const H = 1
Const T = 0

Toss = Int(2 * Rnd())
grpDice.Visible = False

Select Case Toss
Case T
picCoinDice.Image = My.Resources.ely

Case H
picCoinDice.Image = My.Resources.buendia
End Select

If rdoTail.Checked = True And Toss = T Then
Me.Text = "You Lose! :("
Else

Me.Text = "You Win! :)"
End If

If rdoHead.Checked = True And Toss = H Then
Me.Text = "You win! :)"
Else
Me.Text = "You Lose! :("
End If
End Sub

Private Sub btnRoll_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRoll.Click

Dim Roll As Integer

grpCoin.Visible = False
Roll = Int(6 * Rnd()) + 1
Me.Text = "You Lose! :("
Select Case Roll
Case 1
picCoinDice.Image = My.Resources._1

Case 2
picCoinDice.Image = My.Resources._2

Case 3
picCoinDice.Image = My.Resources._3

Case 4
picCoinDice.Image = My.Resources._4

Case 5
picCoinDice.Image = My.Resources._5

Case 6
picCoinDice.Image = My.Resources._6
End Select

If rdo1.Checked = True And Roll = 1 Then
Me.Text = "You win! :)"
End If

If rdo2.Checked = True And Roll = 2 Then
Me.Text = "You win! :)"
End If

If rdo3.Checked = True And Roll = 3 Then
Me.Text = "You win! :)"
End If

If rdo4.Checked = True And Roll = 4 Then
Me.Text = "You win! :)"
End If

If rdo5.Checked = True And Roll = 5 Then
Me.Text = "You win! :)"
End If

If rdo6.Checked = True And Roll = 6 Then
Me.Text = "You win! :)"
End If
End Sub

Private Sub TossCoinToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TossCoinToolStripMenuItem.Click

grpCoin.Visible = True
grpDice.Visible = False
End Sub

Private Sub DiceRollToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiceRollToolStripMenuItem.Click
grpDice.Visible = True
grpCoin.Visible = False
End Sub

Private Sub frmCoinDice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

End Class


3. Save and Run the program..


You can use these photos:















Very Simple Calculator

1. Design the User Interface below.



2. Enter the code as follows:


Public Class frmSimpleCalculator

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

Dim First As Double
Dim Second As Double

First = txtFirstNumber.Text
Second = txtSecondNumber.Text

If rdoAddition.Checked = True Then
lbl3.Text = First + Second
End If

If rdoSubtraction.Checked = True Then
lbl3.Text = First - Second
End If

If rdoMutiplication.Checked = True Then
lbl3.Text = First * Second
End If

If rdoDivision.Checked = True Then
lbl3.Text = First / Second
End If

If rdoIntegerDivision.Checked = True Then
lbl3.Text = First \ Second
End If

If rdoModulus.Checked = True Then
lbl3.Text = First Mod Second
End If

If rdoExponentiation.Checked = True Then
lbl3.Text = First ^ Second
End If

If Double.TryParse(txtFirstNumber.Text, First) = True And Double.TryParse(txtSecondNumber.Text, Second) = True Then

First = txtFirstNumber.Text
Second = txtSecondNumber.Text

If rdoAddition.Checked = True Then
txtResult.Text = First + Second
End If

If rdoSubtraction.Checked = True Then
txtResult.Text = First - Second
End If

If rdoMutiplication.Checked = True Then
txtResult.Text = First * Second
End If

If rdoDivision.Checked = True Then
txtResult.Text = First / Second
End If

If rdoIntegerDivision.Checked = True Then
txtResult.Text = First \ Second
End If

If rdoModulus.Checked = True Then

txtResult.Text = First Mod Second
End If

If rdoExponentiation.Checked = True Then
txtResult.Text = First ^ Second
End If

Else : MsgBox("Enter a number!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Warning")
End If
End Sub

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

End Class

Formatting Menu

1. Start Visual Basic and create a label control within the form.

2. Double click MenuStrip, ToolStrip, PrintDocument, and SaveFileDialog from the Toolbox and do the following:



3. On File Menu, add the following submenu.



4. On Edit Menu, add the following submenu.









5. On Help Menu, add the following submenu.




6. On the code window, enter the following:

Code:


Public Class frmFormattingMenu

Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click

Dim Response As Integer
Response = MsgBox("Are you sure you want to exit", MsgBoxStyle.YesNo + vbQuestion, "My Program")
If Response = vbYes Then
End
End If
End Sub

Private Sub mnuChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuChange.Click

Dim strCaption As String
strCaption = InputBox("Please enter the new text", "Change Text")
If Len(strCaption) = 0 Then
MsgBox("No text Entered", MsgBoxStyle.Exclamation, "Invalid")
Else
lblText.Text = strCaption
End If
End Sub

Private Sub mnuRegular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRegular.Click

lblText.Font = _
New Font(lblText.Font, FontStyle.Regular)
mnuRegular.Checked = True
mnuBold.Checked = False
mnuItalic.Checked = False
End Sub

Private Sub mnuBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBold.Click

lblText.Font = _
New Font(lblText.Font, FontStyle.Bold)
mnuBold.Checked = True
mnuRegular.Checked = False
mnuItalic.Checked = False
End Sub

Private Sub mnuItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItalic.Click

lblText.Font = _
New Font(lblText.Font, FontStyle.Italic)
mnuItalic.Checked = True
mnuRegular.Checked = False
mnuBold.Checked = False
End Sub

Private Sub mnuLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLeft.Click

mnuLeft.Checked = True
mnuRight.Checked = False
mnuCenter.Checked = False
lblText.TextAlign = ContentAlignment.MiddleLeft
End Sub

Private Sub mnuRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRight.Click

mnuRight.Checked = True
mnuLeft.Checked = False
mnuCenter.Checked = False
lblText.TextAlign = ContentAlignment.MiddleRight
End Sub

Private Sub mnuCenter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCenter.Click

mnuCenter.Checked = True
mnuRight.Checked = False
mnuLeft.Checked = False
lblText.TextAlign = ContentAlignment.MiddleCenter
End Sub

Private Sub mnuSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSize.Click

Dim strSize As String
strSize = InputBox("Please enter the desired text size", "Change Size")
If Len(strSize) = 0 Then
MsgBox("No value Entered", MsgBoxStyle.Exclamation, "Invalid")
Else
lblText.Font = New Font(lblText.Font.FontFamily, strSize)
End If
End Sub

Private Sub mnuGray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGray.Click

Me.BackColor = Color.Gray
End Sub

Private Sub mnuWhite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuWhite.Click

Me.BackColor = Color.White
End Sub

Private Sub mnuRed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuRed.Click

Me.BackColor = Color.Red
End Sub

Private Sub mnuBlue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuBlue.Click

Me.BackColor = Color.Blue
End Sub

Private Sub mnuYellow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuYellow.Click

Me.BackColor = Color.Yellow
End Sub

Private Sub mnuGreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuGreen.Click

Me.BackColor = Color.Green
End Sub

Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click

MsgBox("Menu and Dialog Application" & vbCrLf & "by Patrick", MsgBoxStyle.Information, "About")
End Sub

Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click

PrintDocument1.PrinterSettings.Copies = 2
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString(lblText.Text, lblText.Font, Brushes.Blue, 100, 100)
End Sub

Private Sub mnuSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSave.Click

SaveFileDialog1.ShowDialog()
End Sub

Private Sub tsbSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbSave.Click

SaveFileDialog1.ShowDialog()
End Sub

Private Sub tsbPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbPrint.Click

PrintDocument1.PrinterSettings.Copies = 2
PrintDocument1.Print()
End Sub

Private Sub frmFormattingMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub tsbEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbEdit.Click

mnuEdit.ShowDropDown()
End Sub

End Class

MENU SELECTOR

1. Create the user interface similar to the form below. Use PictureBox controls (picMeal, picBurger,picPizza,picCake,picDrinks,picDessert), CheckBox, RadioButton, ListBox and ComboBox within the GroupBox.



2. Enter the program code below by double clicking the form object.


Public Class frmMenuSelector

Private Sub frmMenuSelector_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

lstDrinks.Items.Add("Juice")
lstDrinks.Items.Add("Coffee")
lstDrinks.Items.Add("Softdrinks")
cboDessert.Items.Add("Ice Cream")
cboDessert.Items.Add("Salad")
cboDessert.Items.Add("Pastry")
End Sub

Private Sub cboDessert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDessert.Click

Select Case cboDessert.SelectedIndex
Case 0
picDessert.Image = My.Resources.Ice_cream
Case 1
picDessert.Image = My.Resources.Salad
Case 2
picDessert.Image = My.Resources.Pastry
End Select
End Sub

Private Sub chkBurger_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkBurger.Click

If chkBurger.Checked Then
picBurger.Image = My.Resources.Burger
picBurger.Visible = True
Else
picBurger.Visible = False
End If
End Sub

Private Sub chkCake_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkCake.Click

If chkCake.Checked Then
picCake.Image = My.Resources.Cake
picCake.Visible = True
Else
picCake.Visible = False
End If
End Sub

Private Sub chkPizza_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkPizza.Click

If chkPizza.Checked Then
picPizza.Image = My.Resources.Pizza
picPizza.Visible = True
Else
picPizza.Visible = False
End If
End Sub

Private Sub lstDrinks_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstDrinks.Click

Select Case lstDrinks.SelectedIndex
Case 0
picDrinks.Image = My.Resources.Juice
Case 1
picDrinks.Image = My.Resources.Coffee
Case 2
picDrinks.Image = My.Resources.Softdrinks
End Select
End Sub

Private Sub rdoChicken_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoChicken.Click

If rdoChicken.Checked Then
picMeal.Image = My.Resources.Chicken
picMeal.Visible = True
Else
picMeal.Visible = False
End If
End Sub

Private Sub rdoFish_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoFish.Click

If rdoFish.Checked Then
picMeal.Image = My.Resources.Fish
picMeal.Visible = True
Else
picMeal.Visible = False
End If
End Sub

Private Sub rdoPork_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoPork.Click

If rdoPork.Checked Then
picMeal.Image = My.Resources.Pork
picMeal.Visible = True
Else
picMeal.Visible = False
End If

End Sub
End Class


3. Save and run your program. The program looks like below.




~You can use the photos below.....










Name Display

1. Create a project (Name Display) with two Label controls a TextBox, and a Command Button.

2. Modify the Name property of each of the controls as shown.



3. Change the Text property of the Label to “Enter your name here” and set its AutoSize property to True.

4. Double-click the btnClick button to key in the following:



Public Class frmNameDisplay

Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick.Click
lblMessage.Text = "Hi " & txtName.Text & " Have a nice day!"
End Sub

End Class


5. Run the program.

Color Picker Activity

1. Start Visual Basic and create a standard project Color Picker. Rename Form1 form to Color Picker under Color Picker project.

2. Change the form’s name from Form1 to frmColor and its Text property to “Color Picker”.

3. From the toolbox, select the PictureBox and create a box within the form. Modify its name to “picRed” and select red from the pallete of the BackColor property.

4. Build three more Picture boxes as shown. Change its Name and BackColor property as follows:

picGreen Green

picYellow Yellow

picBlue Blue



5. Create a label control and change its Name property to lblColor. Modify its Autosize property to True. Type “Please point your cursor to a box.” on the Text property and select the desired font in the Font Property.



6. Double click the frmColor to display the Code window Color Picker.vb and enter the following:



Public Class frmColor

Private Sub frmColor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load
End Sub

Private Sub frmColor_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove

lblColor.ForeColor = Color.Chocolate
lblColor.Text = "Please point your cursor to a box."
End Sub

Private Sub picBlue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picBlue.Click

lblColor.ForeColor = Color.Blue
End Sub

Private Sub picBlue_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picBlue.MouseMove

lblColor.Text = "Click this box to change my color to Blue"
End Sub

Private Sub picRed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picRed.Click

lblColor.ForeColor = Color.Red
End Sub

Private Sub picRed_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRed.MouseMove

lblColor.Text = "Click this box to change my color to Red"
End Sub

Private Sub picGreen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picGreen.Click

lblColor.ForeColor = Color.Green
End Sub

Private Sub picGreen_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picGreen.MouseMove

lblColor.Text = "Click this box to change my color to Green"
End Sub

Private Sub picYellow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picYellow.Click

lblColor.ForeColor = Color.Yellow
End Sub

Private Sub picYellow_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picYellow.MouseMove

lblColor.Text = "Click this box to change my color to Yellow"
End Sub

End Class



7. Save your work as Color Picker and run.