Write a VisualBasic program to show different image and description based on the user selection on the combo box.
*set the Visible properties of RichTextBox to False
*set the ComboBox list items to:Â Cat, Dog, Rabbit
Step 1 – Choose an animal
The PictureBox’s Image will be changed to corresponding Image while the SelectedIndexChanged event of the ComboBox is triggered.Â
Tips: The Text of the RichTextBox will be changed at this point.
Step 2 – Checked the Description CheckBox
The RichTextBox will be displayed while the CheckedChanged event of the Description CheckBox is triggered.
You may use the following description:
-Cat: The cat is a domestic species of small carnivorous mammal.
-Dog: The dog or domestic dog, is a domesticated descendant of the wolf, characterized by an upturning tail.
-Rabbit: The rabbits also known as bunnies or bunny rabbits, are small mammals in the family Leporidae (along with the hare) of the order Lagomorpha (along with the pika).
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmAnimal
  Inherits System.Windows.Forms.Form
  'Form overrides dispose to clean up the component list.
  <System.Diagnostics.DebuggerNonUserCode()> _
  Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    Try
      If disposing AndAlso components IsNot Nothing Then
        components.Dispose()
      End If
    Finally
      MyBase.Dispose(disposing)
    End Try
  End Sub
  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer
  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer. Â
  'Do not modify it using the code editor.
  <System.Diagnostics.DebuggerStepThrough()> _
  Private Sub InitializeComponent()
    Me.cbAnimal = New System.Windows.Forms.ComboBox()
    Me.pbPhoto = New System.Windows.Forms.PictureBox()
    Me.txtDescription = New System.Windows.Forms.RichTextBox()
    Me.Label1 = New System.Windows.Forms.Label()
    CType(Me.pbPhoto, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'cbAnimal
    '
    Me.cbAnimal.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
    Me.cbAnimal.FormattingEnabled = True
    Me.cbAnimal.Items.AddRange(New Object() {"Cat", "Dog", "Rabbit"})
    Me.cbAnimal.Location = New System.Drawing.Point(41, 58)
    Me.cbAnimal.Name = "cbAnimal"
    Me.cbAnimal.Size = New System.Drawing.Size(175, 39)
    Me.cbAnimal.TabIndex = 0
    '
    'pbPhoto
    '
    Me.pbPhoto.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom
    Me.pbPhoto.Location = New System.Drawing.Point(236, 13)
    Me.pbPhoto.Name = "pbPhoto"
    Me.pbPhoto.Size = New System.Drawing.Size(213, 145)
    Me.pbPhoto.TabIndex = 1
    Me.pbPhoto.TabStop = False
    '
    'txtDescription
    '
    Me.txtDescription.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
    Me.txtDescription.Location = New System.Drawing.Point(41, 179)
    Me.txtDescription.Name = "txtDescription"
    Me.txtDescription.Size = New System.Drawing.Size(414, 90)
    Me.txtDescription.TabIndex = 2
    Me.txtDescription.Text = ""
    '
    'Label1
    '
    Me.Label1.AutoSize = True
    Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
    Me.Label1.Location = New System.Drawing.Point(35, 13)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(187, 31)
    Me.Label1.TabIndex = 3
    Me.Label1.Text = "Select Animal:"
    '
    'frmAnimal
    '
    Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
    Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
    Me.ClientSize = New System.Drawing.Size(485, 295)
    Me.Controls.Add(Me.Label1)
    Me.Controls.Add(Me.txtDescription)
    Me.Controls.Add(Me.pbPhoto)
    Me.Controls.Add(Me.cbAnimal)
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "frmAnimal"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Animal"
    CType(Me.pbPhoto, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)
    Me.PerformLayout()
  End Sub
  Friend WithEvents cbAnimal As System.Windows.Forms.ComboBox
  Friend WithEvents pbPhoto As System.Windows.Forms.PictureBox
  Friend WithEvents txtDescription As System.Windows.Forms.RichTextBox
  Friend WithEvents Label1 As System.Windows.Forms.Label
End Class
Public Class frmAnimal
  Private Sub cbAnimal_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbAnimal.SelectedIndexChanged
    If cbAnimal.SelectedIndex = 0 Then
      txtDescription.Text = "The cat is a domestic species of small carnivorous mammal."
      pbPhoto.BackgroundImage = AnimalImage.My.Resources.Cat
    End If
    If cbAnimal.SelectedIndex = 1 Then
      txtDescription.Text = "The dog or domestic dog, is a domesticated descendant of the wolf, characterized by an upturning tail."
      pbPhoto.BackgroundImage = AnimalImage.My.Resources.Dog
    End If
    If cbAnimal.SelectedIndex = 2 Then
      txtDescription.Text = "The rabbits also known as bunnies or bunny rabbits, are small mammals in the family Leporidae (along with the hare) of the order Lagomorpha (along with the pika)."
      pbPhoto.BackgroundImage = AnimalImage.My.Resources.Rabbit
    End If
  End Sub
End Class
Comments
Leave a comment