100% found this document useful (1 vote)
50 views14 pages

For Check Boxes: "Arial" "Arial"

The document contains code examples for using different form controls in Visual Basic, including checkboxes, radio buttons, list boxes, and creating a simple calculator application. It demonstrates how to handle events for these controls to update properties like fonts, colors, and performing basic math operations with user input values. Overall the code snippets provide examples of working with common form controls and user interactions in Visual Basic applications.

Uploaded by

Siva2cool
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
50 views14 pages

For Check Boxes: "Arial" "Arial"

The document contains code examples for using different form controls in Visual Basic, including checkboxes, radio buttons, list boxes, and creating a simple calculator application. It demonstrates how to handle events for these controls to update properties like fonts, colors, and performing basic math operations with user input values. Overall the code snippets provide examples of working with common form controls and user interactions in Visual Basic applications.

Uploaded by

Siva2cool
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

For check boxes

Public Class Form4

Private Sub CheckBox1_CheckedChanged(ByVal sender


As System.Object, ByVal e As System.EventArgs) Handles
CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
Label1.Font = New Font("Arial", 14,
FontStyle.Bold)
Else
Label1.Font = New Font("Arial", 14,
FontStyle.Regular)
End If

End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender


As System.Object, ByVal e As System.EventArgs) Handles
CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
Label1.Font = New Font("Arial", 14,
FontStyle.Italic)
Else
Label1.Font = New Font("Arial", 14,
FontStyle.Regular)
End If
End Sub

Private Sub Form4_Load(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load

End Sub
End Class
For radio button

Public Class Form5

Private Sub RadioButton1_CheckedChanged(ByVal


sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
Label1.ForeColor = Color.Red
End If
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal


sender As System.Object, ByVal e As System.EventArgs)
Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
Label1.ForeColor = Color.Green
End If
End Sub
End Class
For list box

Public Class Form6

Private Sub Button1_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim x
x = InputBox("Enter item to add")
ListBox1.Items.Add(x)
End Sub

Private Sub Button2_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub

Private Sub Button3_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
MsgBox("Selected Item=" &
ListBox1.SelectedItem)
End Sub
Private Sub Button4_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
MsgBox("Selected Index =" &
ListBox1.SelectedIndex)
End Sub

Private Sub Button5_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
ListBox1.Sorted = True
End Sub

Private Sub Button6_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button6.Click
Dim x As String
x = InputBox("Enter item to replace")
ListBox1.Items.Insert(ListBox1.SelectedIndex,
x)
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub

Private Sub Button7_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button7.Click
Dim x As String
Dim i
x = InputBox("Enter item to search")
i = ListBox1.FindStringExact(x)
If i = -1 Then
MsgBox("No suh item")
Else
MsgBox("item found")
End If
End Sub
End Class
Assignment
Font

Public Class Form8


Private fname As String = "Arial"
Private fstyle As String = "Regular"
Private fsize As Short = 8
Private Sub Form8_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim i
For i = 0 To FontFamily.Families.Length - 1
ListBox1.Items.Add(FontFamily.Families(i).Name)
Next
ListBox2.Items.Add("Regular")
ListBox2.Items.Add("Bold")
ListBox2.Items.Add("Italic")
For i = 4 To 72 Step 4
ListBox3.Items.Add(i)
Next
assign()
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal


sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ListBox1.SelectedItem
fname = ListBox1.SelectedItem
assign()
End Sub

Private Sub ListBox2_SelectedIndexChanged(ByVal


sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox2.SelectedIndexChanged
TextBox2.Text = ListBox2.SelectedItem
fstyle = ListBox2.SelectedItem
assign()
End Sub

Private Sub ListBox3_SelectedIndexChanged(ByVal


sender As System.Object, ByVal e As System.EventArgs)
Handles ListBox3.SelectedIndexChanged
TextBox3.Text = ListBox3.SelectedItem
fsize = ListBox3.SelectedItem
assign()
End Sub
Public Sub assign()
Try
Dim st As String = fstyle.ToLower
Select Case st
Case "regular"
TextBox4.Font = New Font(fname,
fsize, FontStyle.Regular)
Case "bold"
TextBox4.Font = New Font(fname,
fsize, FontStyle.Bold)
Case "italic"
TextBox4.Font = New Font(fname,
fsize, FontStyle.Italic)
End Select
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender


As System.Object, ByVal e As System.EventArgs) Handles
CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox4.Font = New Font(fname, fsize,
FontStyle.Underline)
Else
TextBox4.Font = New Font(fname, fsize,
FontStyle.Regular)
End If
End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender


As System.Object, ByVal e As System.EventArgs) Handles
CheckBox2.CheckedChanged
If CheckBox2.Checked = True Then
TextBox4.Font = New Font(fname, fsize,
FontStyle.Strikeout)
Else
TextBox4.Font = New Font(fname, fsize,
FontStyle.Regular)
End If
End Sub
End Class
To show a form

Public Class Form9

Private Sub Button1_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim f As New Form8
f.Show()
End Sub
End Class

Calculator

Public Class Form10


Dim a, b As Int64

Dim op As String
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If Button1.Enabled = True And TextBox1.Text =
"" Then

TextBox1.Text = CInt(Button1.Text)
Else
TextBox1.Text = TextBox1.Text &
Button1.Text
End If
End Sub

Private Sub Button2_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
If Button2.Enabled = True And TextBox1.Text =
"" Then

TextBox1.Text = CInt(Button2.Text)
Else
TextBox1.Text = TextBox1.Text &
Button2.Text
End If
End Sub

Private Sub Button3_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
If Button3.Enabled = True And TextBox1.Text =
"" Then

TextBox1.Text = CInt(Button3.Text)
Else
TextBox1.Text = TextBox1.Text &
Button3.Text
End If
End Sub
Private Sub Button4_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
If Button4.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button4.Text)
Else
TextBox1.Text = TextBox1.Text &
Button4.Text
End If
End Sub

Private Sub Button5_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
If Button5.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button5.Text)
Else
TextBox1.Text = TextBox1.Text &
Button5.Text
End If
End Sub

Private Sub Button6_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button6.Click
If Button6.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button6.Text)
Else
TextBox1.Text = TextBox1.Text &
Button6.Text
End If
End Sub

Private Sub Button7_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button7.Click
If Button7.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button7.Text)
Else
TextBox1.Text = TextBox1.Text &
Button7.Text
End If
End Sub

Private Sub Button8_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button8.Click
If Button8.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button8.Text)
Else
TextBox1.Text = TextBox1.Text &
Button8.Text
End If
End Sub

Private Sub Button9_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button9.Click
If Button9.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button9.Text)
Else
TextBox1.Text = TextBox1.Text &
Button9.Text
End If
End Sub

Private Sub Button11_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button11.Click
If Button11.Enabled = True And TextBox1.Text =
"" Then
TextBox1.Text = CInt(Button11.Text)
Else
TextBox1.Text = TextBox1.Text &
Button11.Text
End If
End Sub

Private Sub Button10_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button10.Click
a = CInt(TextBox1.Text)
TextBox1.Text = ""
op = "+"
End Sub

Private Sub Button12_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button12.Click
a = CInt(TextBox1.Text)
TextBox1.Text = ""
op = "*"
End Sub

Private Sub Button13_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button13.Click
a = CInt(TextBox1.Text)
TextBox1.Text = ""
op = "-"
End Sub

Private Sub Button14_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button14.Click
a = CInt(TextBox1.Text)
TextBox1.Text = ""
op = "/"
End Sub

Private Sub Button15_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button15.Click
TextBox1.Text = ""
End Sub

Private Sub Button16_Click(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
Button16.Click
b = CInt(TextBox1.Text)
Select Case op
Case "+"
TextBox1.Text = a + b
Case "*"
TextBox1.Text = a * b
Case "/"
TextBox1.Text = a / b
Case "-"
TextBox1.Text = a - b
End Select
End Sub
End Class

You might also like