Lab Manual 1 (Introduction)
Lab Manual 1 (Introduction)
In the following example, let us create two groups of radio buttons and use their CheckedChanged events
for changing the BackColor and ForeColor property of the form.
Let's double click on the radio buttons and put the follow code in the opened window.
1
End Class
Example 2 adding lists in the list box when the form loads
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.Items.Add("Canada")
ListBox1.Items.Add("USA")
ListBox1.Items.Add("UK")
ListBox1.Items.Add("Japan")
ListBox1.Items.Add("Russia")
ListBox1.Items.Add("China")
ListBox1.Items.Add("India")
End Sub
2
Clicking the Select button displays a message box with the user's choice:
Example 3: In this example, we will fill up a list box with items, retrieve the total number of items in the
list box, sort the list box, remove some items and clear the entire list box.
3
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub
'populates the list
Private Sub Button1_Click_1(sender As Object, e As EventArgs) _
Handles Button1.Click
ListBox1.Items.Add("Safety")
ListBox1.Items.Add("Security")
ListBox1.Items.Add("Governance")
ListBox1.Items.Add("Good Music")
ListBox1.Items.Add("Good Movies")
ListBox1.Items.Add("Good Books")
ListBox1.Items.Add("Education")
ListBox1.Items.Add("Roads")
ListBox1.Items.Add("Health")
ListBox1.Items.Add("Food for all")
ListBox1.Items.Add("Shelter for all")
ListBox1.Items.Add("Industrialisation")
ListBox1.Items.Add("Peace")
ListBox1.Items.Add("Liberty")
ListBox1.Items.Add("Freedom of Speech")
End Sub
Sorting the list
Private Sub Button2_Click (sender As Object, e As EventArgs) _ Handles Button2.Click
ListBox1.Sorted = True
End Sub
clears the list
Private Sub Button3_Click(sender As Object, e As EventArgs) _
Handles Button3.Click
ListBox1.Items.Clear ()
End Sub
Removing the selected item
Private Sub Button4_Click(sender As Object, e As EventArgs) _
Handles Button4.Click
ListBox1.Items.Remove (ListBox1.SelectedItem.ToString)
End Sub
Counting the number of items
Private Sub Button5_Click(sender As Object, e As EventArgs) _
Handles Button5.Click
Label1.Text = ListBox1.Items.Count
End Sub
Displaying the selected item on the third label
Private Sub ListBox1_SelectedIndexChanged (sender As Object, e As EventArgs) _
Handles ListBox1.SelectedIndexChanged
Label3.Text = ListBox1.SelectedItem.ToString()
End Sub
4
End Class
Example 4
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "Labe Exercise "
End Sub
'to sends the selected items to the list box
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.SelectedIndex > -1 Then
Dim sindex As Integer
sindex = ComboBox1.SelectedIndex
Dim sitem As Object
sitem = ComboBox1.SelectedItem
ListBox1.Items.Add(sitem)
End If
End Sub
'To populate the list
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ComboBox1.Items.Add("Safety")
ComboBox1.Items.Add("Security")
ComboBox1.Items.Add("Governance")
ComboBox1.Items.Add("Health")
ComboBox1.Items.Add("Food for all")
ComboBox1.Items.Add("Shelter for all")
ComboBox1.Items.Add("Peace")
ComboBox1.Items.Add("Liberty")
ComboBox1.Items.Add("Freedom of Speech")
End Sub
Sorting the list
Private Sub Button3_Click(sender As Object, e As EventArgs)
ComboBox1.Sorted = True
End Sub
Clears the list
Private Sub Button4_Click(sender As Object, e As EventArgs)
ComboBox1.Items.Clear()
End Sub
5
Example 5
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) _
Handles MyBase.Load
'create two progress bars
Dim ProgressBar1 As ProgressBar
Dim ProgressBar2 As ProgressBar
ProgressBar1 = New ProgressBar()
ProgressBar2 = New ProgressBar()
'set position
ProgressBar1.Location = New Point(10, 10)
ProgressBar2.Location = New Point(10, 50)
'set values
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 200
ProgressBar1.Value = 130
ProgressBar2.Minimum = 0
ProgressBar2.Maximum = 100
ProgressBar2.Value = 40
'add the progress bar to the form
Me.Controls.Add(ProgressBar1)
Me.Controls.Add(ProgressBar2)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
End Class
Example 6: basic Operators
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
MsgBox(8 + 9)
End Sub
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Label1.Click
6
Label1.Text = Num1 + Num2
End Sub