1.
CLICKCOUNT EVENT
Form Design:
Public Class Form1
Dim clickcount As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
clickcount += 1
MessageBox.Show(" button clicked " & clickcount & " times.")
End Sub
End Class
OUTPUT:
2. IMAGE LIST
Form Design
Public Class ImageList
Dim n As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
PictureBox1.Image = ImageList1.Images(n)
If (n = ImageList1.Images.Count - 1) Then
n = 0
Else
n += 1
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Timer1.Stop()
End Sub
End Class
OUTPUT:
3.RICH TEXTBOX CONTROL
Form Design:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
RichTextBox1.Font = New Font("Welcome To RichTextboxes", 16)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
RichTextBox1.Font = New Font("Welcome To RichTextboxes", 16,
FontStyle.Bold)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
RichTextBox1.Font = New Font("Welcome To RichTextboxes", 16,
FontStyle.Underline)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
RichTextBox1.Font = New Font("Welcome To RichTextboxes", 16,
FontStyle.Italic)
End Sub
End Class
OUTPUT:
4.MENUS AND DIALOGS
Form Design:
Public Class Form1
Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles NewToolStripMenuItem.Click
TextBox1.Text = ""
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles SaveToolStripMenuItem.Click
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName,
TextBox1.Text, False)
End If
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles OpenToolStripMenuItem.Click
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text =
My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ExitToolStripMenuItem.Click
MessageBox.Show(" You Opited Exit")
End Sub
Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CopyToolStripMenuItem.Click
TextBox1.Copy()
End Sub
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CutToolStripMenuItem.Click
TextBox1.Cut()
End Sub
Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles PasteToolStripMenuItem.Click
TextBox1.Paste()
End Sub
Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
TextBox1.SelectAll()
End Sub
Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles FontToolStripMenuItem.Click
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Font = FontDialog1.Font
End If
End Sub
Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ColorToolStripMenuItem.Click
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.ForeColor = ColorDialog1.Color
End If
End Sub
End Class
OUTPUT:
5. EXCEPTION HANDLING
Form Design:
Person file:
Public Class Person
Friend Const DEFAULT_AGE As Integer = 0
Friend Const MIN_AGE As Integer = 1
Friend Const MAX_AGE As Integer = 100
Dim attrAge As Integer
Property Age As Integer
Get
Return attrAge
End Get
Set(ByVal value As Integer)
If (value < MIN_AGE Or value > MAX_AGE) Then
Throw New ArgumentOutOfRangeException
Else
attrAge = value
End If
End Set
End Property
Sub New()
attrAge = DEFAULT_AGE
End Sub
End Class
Form file:
Public Class Form1
Private Sub btnMakePerson_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnMakePerson.Click
Dim p As Person = New Person
Try
p.Age = TxtAge.Text
MsgBox("New age is " + p.Age.ToString + ".")
Catch ex As InvalidCastException
MsgBox("Age must be a numeric value.")
Catch ex As ArgumentOutOfRangeException
MsgBox("Age must be between " + Person.MIN_AGE.ToString + " and " +
Person.MAX_AGE.ToString + ".")
End Try
End Sub
End Class
OUTPUT:
6. FUNCTIONS
Form Design:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim result As Integer
result = addFunction(TextBox1.Text, TextBox2.Text)
MessageBox.Show("The result is :" & result)
End Sub
Private Function addFunction(ByVal a As Integer, ByVal b As Integer) As
Integer
Dim sum As Integer
sum = a + b
Return sum
End Function
Private Sub add(ByVal a As Integer, ByVal b As Integer)
Dim sum As Integer
sum = a + b
MessageBox.Show("The sum of too no.is:" & sum)
End Sub
End Class
OUTPUT:
7. POLYMORPHISM
Module Module1
Sub Main()
Console.WriteLine("Welcome")
Dim rect1 As New cRectangle(2, 3)
Dim cube1 As New cCube(2, 3, 4)
Console.WriteLine("Area of rectangle is " & rect1.GetArea)
Console.WriteLine("Area of cube is " & cube1.getArea)
Console.ReadLine()
End Sub
End Module
Public Class cCube
Inherits cRectangle
Private _Depth As Integer = 0
Sub New()
MyBase.New()
End Sub
Sub New(ByVal w As Integer, ByVal h As Integer, ByVal d As Integer)
MyBase.New(w, h)
_Depth = d
End Sub
Overloads Function getArea()
Return _width * _height * _Depth
End Function
End Class
Public Class cRectangle
Protected _width As Integer = 0
Protected _height As Integer = 0
Sub New()
End Sub
Sub New(ByVal width As Integer, ByVal height As Integer)
_width = width
_height = height
End Sub
Function GetArea()
Return _width * _height
End Function
End Class
OUTPUT:
8. INHERITANCE
Form Design:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ob As New result(".NET", 85)
ob.Show()
End Sub
End Class
Public Class Stud
Public sub_Name As String
Public Sub New(ByVal x As String)
sub_Name = x
End Sub
End Class
Public Class result
Inherits Stud
Dim Marks As Integer
Public Sub New(ByVal sub_na As String, ByVal x As Integer)
MyBase.New(sub_na)
Marks = x
End Sub
Public Function Show() As Integer
MessageBox.Show(" Subject Name: " & sub_Name & " Marks: " & Marks)
Return (0)
End Function
End Class
Output:
9. WEB APPLICATION
Form Design:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Process.Start("www.google.com")
End Sub
End Class
OUTPUT:
10. VALIDATION CONTROLS
Form Design:
Validation Controls:
1.Username : Requireddfilevalidator->ErrorMessage:*un is
required,Display:Dynamic,ControlToValidate:textBox1,SetFocusOn Error:True
2.Email:Rangevalidator>ErrorMessage:*invalidEmail,Display:Dynamic,ControlToValidate:Textbox2,SetFo
cusOnError:tTrue,validation expression:internet Expression
3.Password: requiredfilevalidator->ErrorMessage:*Pass is
required,Display:Dynamic,ControlToValidate:textBox3,SetFocusOnError:True,
TextBox3->TextMode:Password
4.Resetpassword: comparevalidator-
>ErrorMessage:*retypepasswordDisplay:Dynamic,ControlToValidate:TextBox4,SetFocusOnError:True,Co
ntrolToCompare:TextBox3
TextBox4->TextboxMode:password
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Response.Write("your login to Successfully")
End Sub
End Class
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click
Response.Write("your login to Successfully")
End Sub
End Class
Output:
11. REDIRECTION CONCEPT
Form Design 1:
Form 1:
Public Class Form1
Public GetValue As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Fm As New Form2
If Fm.ShowDialog = Windows.Forms.DialogResult.OK Then
Label1.Text = GetValue
End If
End Sub
End Class
Form Design2:
Form2:
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Form1.GetValue = TextBox1.Text
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
End Class
OUTPUT:
13. DATA GRID CONTROL
Form Design
Public Class Form1
Dim i As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.DataGridView1.Rows.Add(TextBox1.Text, TextBox2.Text, TextBox3.Text,
TextBox4.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If DataGridView1.SelectedRows.Count > 0 Then
For i As Integer = DataGridView1.SelectedRows.Count - 1 To 0 step -1
DataGridView1.Rows.RemoveAt(DataGridView1.SelectedRows(i).Index)
Next
Else
MessageBox.Show("No Rows To Select")
End If
End Sub
End Class
OUTPUT: