gui lab manual

99
GUI Lab Manual 1 B. Raju, Asst. Professor, KITS, Warangal- 506 015 INDEX SL.NO LIST OF PROGRAMS 1. To perform all Arithmetic operations. 2. To compare two values using relational operators. 3. To find maximum of 3 numbers. 4. To check whether a given number is even or odd. 5. To check whether a given number is Palindrome or not. 6. To find factorial of a given number. 7. To check whether a given number is Armstrong or not. 8. To print Fibonacci series. 9. To compare two strings. 10. To demo on arrays. 11. To demo on select case. 12. To demo on threads. 13. For binary search. 14. To find sum of digits. 15. To demonstrate Structured exceptional handling. 16. To demonstrate Unstructured exceptional handling. 17. To demonstrate Resume next. WINDOWS APPLICATIONS 18. To implement all arithmetic operations using buttons. 19. To implement all arithmetic operations using radio buttons. 20. To demo group box. 21. To implement alarm.

Upload: bunny-karthik

Post on 22-Nov-2015

27 views

Category:

Documents


0 download

DESCRIPTION

Hi guys this may be useful to you.

TRANSCRIPT

  • GUI Lab Manual 1

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    INDEX

    SL.NO LIST OF PROGRAMS

    1. To perform all Arithmetic operations.

    2. To compare two values using relational operators.

    3. To find maximum of 3 numbers.

    4. To check whether a given number is even or odd.

    5. To check whether a given number is Palindrome or not.

    6. To find factorial of a given number.

    7. To check whether a given number is Armstrong or not.

    8. To print Fibonacci series.

    9. To compare two strings.

    10. To demo on arrays.

    11. To demo on select case.

    12. To demo on threads.

    13. For binary search.

    14. To find sum of digits.

    15. To demonstrate Structured exceptional handling.

    16. To demonstrate Unstructured exceptional handling.

    17. To demonstrate Resume next.

    WINDOWS APPLICATIONS

    18. To implement all arithmetic operations using buttons.

    19. To implement all arithmetic operations using radio buttons.

    20. To demo group box.

    21. To implement alarm.

  • GUI Lab Manual 2

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    22. To implement picker.

    23. To implement progress bar.

    24. To implement track bar.

    25. To implement mouse tracking.

    26. To demo on Check box.

    27. To demo on combo box for geometric shapes.

    28. To demo on tab controls for geometric shapes.

    29. To paint using mouse.

    30. To implement static logins.

    31. To implement notepad application.

    32. To add and remove List Box items.

    33. To demo on color dialogs.

    34. To show time.

    35. To demo on validations.

    36. To show corresponding character.

    37. To demo on calculator.

    Introduction to ADO.NET

    DATABASE CONNECTION PROGRAMS

    38. To retrieve data from database using console application.

    39. To check username & password from the database.

    40. To implement insertion, updating, deletion & view the data from the database.

    Signature

  • GUI Lab Manual 3

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    CONSOLE APPLICATIONS

  • GUI Lab Manual 4

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    PROGRAM TO PERFORM ALL ARTHMETIC OPERATIONS

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a, b As Integer

    WriteLine("Enter any 2 Integers")

    a = ReadLine()

    b = ReadLine()

    WriteLine("Sum of Give Integers is {0}", a + b)

    WriteLine("Difference of Give Integers is {0}", a - b)

    WriteLine("Product of Give Integers is {0}", a * b)

    WriteLine("Ratio of Give Integers is {0}", a \ b)

    ReadLine()

    End Sub

    End Module

    Output:

    Enter any 2 Integers

    12

    14

    Sum of Given Integers is 26

    Difference of Given Integers is -2

  • GUI Lab Manual 5

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Product of Given Integers is 168

    Ratio of Given Integers is 0

  • GUI Lab Manual 6

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    PROGRAM TO COMPARE TWO VALUES USING RELATIONAL OPERATORS

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a, b As Integer

    WriteLine("Enter any 2 integers")

    a = ReadLine()

    b = ReadLine()

    If a > b Then

    WriteLine("{0} is greater than {1}", a, b)

    Else

    If a < b Then

    WriteLine("{0} is less than {1}", a, b)

    Else

    WriteLine("{0} is equal to {1}", a, b)

    End If

    End If

    ReadLine()

    End Sub

  • GUI Lab Manual 7

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Module

    Output:

    Enter any 2 integers

    12

    14

    12 is less than 14

  • GUI Lab Manual 8

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO FIND MAXIMUM OF 3 NUMBERS

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a, b, c As Integer

    WriteLine("Enter any three integers")

    a = ReadLine()

    b = ReadLine()

    c = ReadLine()

    If a > b Then

    If a > c Then

    WriteLine("{0} is Greater", a)

    Else

    WriteLine("{0} is Greater", c)

    End If

    Else

    If b > c Then

    WriteLine("{0} is Greater", b)

    Else

  • GUI Lab Manual 9

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    WriteLine("{0} is Greater", c)

    End If

    End If

    ReadLine()

    End Sub

    End Module

    Output:

    Enter any three integers

    12

    15

    13

    15 is Greater

  • GUI Lab Manual 10

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO CHECK WHETHER A GIVEN NUMBER IS EVEN OR ODD

    Imports System.Console

    Module Module1

    Sub Main()

    Dim n As Integer

    WriteLine("Enter a number")

    n = ReadLine()

    If n Mod 2 = 0 Then

    WriteLine("{0} is an even number", n)

    Else

    WriteLine("{0} is an odd number", n)

    End If

    ReadLine()

    End Sub

    End Module

    Output:

    Enter a number

    12

    12 is an even number

  • GUI Lab Manual 11

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO CHECH WHETHER A GIVEN NUMBER IS PALINDROME OR NOT

    Imports System.Console

    Module Module1

    Sub Main()

    Dim n, x, r, i, s As Integer

    WriteLine("Enter a number")

    n = ReadLine()

    x = n

    s = 0

    While n > 0

    r = n Mod 10

    s = s * 10 + r

    n = n / 10

    End While

    If x = s Then

    WriteLine("{0} is a palindrome", x)

    Else

    WriteLine("{0} is not palindrome", x)

    End If

    ReadLine()

  • GUI Lab Manual 12

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    End Module

    Output:

    Enter a number

    121

    121 is a palindrome

  • GUI Lab Manual 13

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO FIND FACTORIAL OF A GIVEN NUMBER

    Imports System.Console

    Module Module1

    Sub Main()

    Dim f, n, i As Integer

    WriteLine("Enter an Integer")

    n = ReadLine()

    f = 1

    For i = 1 To n Step 1

    f = f * i

    Next

    WriteLine("Factorial of {1} is {0}", f, n)

    ReadLine()

    End Sub

    End Module

    Output:

    Enter an Integer

    5

    Factorial of 5 is 120

  • GUI Lab Manual 14

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG OR NOT

    Imports System.Console

    Module Module1

    Sub Main()

    Dim n, x, y, r, s As Integer

    WriteLine("Enter any integer")

    n = ReadLine()

    x = n

    s = 0

    While n > 0

    r = n Mod 10

    y = r * r * r

    s = s + y

    n = n \ 10

    End While

    If x = s Then

    WriteLine("{0} is an Armstrong number", x)

    Else

    WriteLine("{0} is not an Armstrong number", x)

    End If

  • GUI Lab Manual 15

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    ReadLine()

    End Sub

    End Module

    Output:

    Enter any integer

    153

    153 is an Armstrong number

  • GUI Lab Manual 16

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO PRINT FIBONACCI SERIES

    Imports System.Console

    Module Module1

    Sub Main()

    Dim m, i, f1, f2, f3 As Integer

    WriteLine("Enter number of terms:")

    m = ReadLine()

    f1 = 0

    f2 = 1

    WriteLine("Fibonacci series:")

    WriteLine(f1)

    WriteLine(f2)

    For i = 1 To m - 2

    f3 = f1 + f2

    WriteLine(f3)

    f1 = f2

    f2 = f3

    Next i

    ReadLine()

    End Sub

  • GUI Lab Manual 17

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Module

    Output:

    Enter number of terms

    5

    Fibonacci series:

    0

    1

    1

    2

    3

  • GUI Lab Manual 18

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO COMPARE TWO STRINGS

    Imports System.Console

    Module Module1

    Sub Main()

    Dim s1, s2 As String

    WriteLine("Enter two strings:")

    s1 = ReadLine()

    s2 = ReadLine()

    If s1 = s2 Then

    WriteLine("Strings are equal")

    Else

    WriteLine("Strings are not equal")

    End If

    ReadLine()

    End Sub

    End Module

    Output:

    Enter two strings

    Hi

    Hello

    Strings are not equal

  • GUI Lab Manual 19

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON ARRAYS

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a(20), n, s, i As Integer

    WriteLine("Enter array size:")

    n = ReadLine()

    WriteLine("Enter array elements:")

    For i = 1 To n

    a(i) = ReadLine()

    Next

    s = 0

    For i = 1 To n

    s = s + a(i)

    Next

    WriteLine("Sum of array elements is {0}", s)

    ReadLine()

    End Sub

    End Module

  • GUI Lab Manual 20

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Output:

    Enter array size:

    4

    Enter array elements:

    12

    14

    15

    16

    Sum of array elements is 57

  • GUI Lab Manual 21

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON SELECT CASE

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a, b, k As Integer

    WriteLine("Enter any two integers:")

    a = ReadLine()

    b = ReadLine()

    WriteLine("1.Addition")

    WriteLine("2.Subtraction")

    WriteLine("3.Multiplication")

    WriteLine("4.Division")

    WriteLine("Select the operation to be performed:")

    k = ReadLine()

    Select Case k

    Case 1

    WriteLine({0} + {1} is {2}, a, b, a + b)

    Case 2

    WriteLine({0} - {1} is {2}, a, b, a - b)

  • GUI Lab Manual 22

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Case 3

    WriteLine({0} * {1} is {2}, a, b, a * b)

    Case 4

    WriteLine({0} / {1} is {2}, a, b, a \ b)

    Case Else

    WriteLine("Invalid choice")

    End Select

    ReadLine()

    End Sub

    End Module

    Output:

    Enter any two integers:

    12

    14

    1. Addition

    2. Subtraction

    3. Multiplication

    4. Division

    Select the operation to be performed

    4

    12 / 14 is 0

  • GUI Lab Manual 23

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON THREADS

    Imports System.Console

    Imports System.Threading

    Module Module1

    Private t1 As Thread

    Private t2 As Thread

    Sub Main()

    t1 = New Thread(AddressOf Thread1)

    t2 = New Thread(AddressOf Thread2)

    t1.Name = "Thread1"

    t2.Name = "Thread2"

    t1.Start()

    t2.Start()

    ReadLine()

    End Sub

    Sub Thread1()

    WriteLine("Thread1 is executed")

    End Sub

    Sub Thread2()

    WriteLine("Thread2 is executed")

    End Sub

  • GUI Lab Manual 24

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Module

    Output:

    Thread1 is executed

    Thread2 is executed

  • GUI Lab Manual 25

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT BINARY SEARCH

    Imports System.Console

    Module Module1

    Sub Main()

    Dim a(20), n, k, l, h, m, i As Integer

    WriteLine("Enter the size of array:")

    n = ReadLine()

    WriteLine("Enter the elements into array:")

    For i = 1 To n

    a(i) = ReadLine()

    Next i

    WriteLine("Enter the element to be searched:")

    k = ReadLine()

    l = 1

    h = n

    While l

  • GUI Lab Manual 26

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    If k < a(m) Then

    h = m - 1

    Else

    l = m + 1

    End If

    End If

    End While

    If k a(m) Then

    WriteLine("Element not found")

    End If

    ReadLine()

    End Sub

    End Module

    Output:

    Enter the size of array:

    4

    Enter the elements into array:

    12

  • GUI Lab Manual 27

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    13

    14

    15

    Enter the element to be searched:

    14

    Element found at 3

  • GUI Lab Manual 28

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    PROGRAM FOR FINDING THE SUM OF DIGITS IN A NUMBER

    Imports System.Console

    Module Module1

    Sub Main()

    Dim n, s, r, t As Integer

    s = 0

    WriteLine("Enter the number to find the sum of its digits:")

    n = ReadLine()

    t = n

    While n > 0

    r = n Mod 10

    s = s + r

    n = n \ 10

    End While

    WriteLine("Sum of digits of {0} is {1}", t, s)

    ReadLine()

    End Sub

    End Module

  • GUI Lab Manual 29

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Output:

    Enter the number to find the sum of its digits:

    164

    Sum of digits of 164 is 11

  • GUI Lab Manual 30

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMONSTRATE STRUCTURED EXCEPTION HANDLING

    Imports System.Console

    Module Module1

    Sub Main()

    Dim n1, n2, n3 As Integer

    Dim str As String

    WriteLine("Enter two numbers and a string:")

    n1 = CType(ReadLine(), Integer)

    n2 = CType(ReadLine(), Integer)

    str = ReadLine()

    Try

    n3 = n1 / n2

    n1 = CType(str, Integer)

    Catch ex1 As InvalidCastException

    WriteLine("There is a casting Error")

    Catch ex2 As OverflowException

    WriteLine("there is an overflow exception error")

    Finally

    WriteLine("Please enter valid Input")

    End Try

  • GUI Lab Manual 31

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    ReadLine()

    End Sub

    End Module

    Output:

    Enter two numbers and a string

    12

    13

    Hi

    There is a casting Error

    Please enter valid Input

  • GUI Lab Manual 32

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMONSTRATE UNSTRUCTURED EXCEPTIONAL HANDLING

    Imports System.Console

    Module Module1

    Sub Main()

    Dim x, y, z As Integer

    On Error GoTo Handler

    WriteLine("Enter two values")

    x = ReadLine()

    y = ReadLine()

    z = x / y

    WriteLine("Division is {0}", z)

    ReadLine()

    Exit Sub

    Handler:

    WriteLine("Divison by 0 is an exception")

    ReadLine()

    End Sub

    End Module

  • GUI Lab Manual 33

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Output:

    Enter two values

    13

    0

    Division by 0 is an exception

  • GUI Lab Manual 34

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMONSTRATE RESUME NEXT

    Imports System.Console

    Module Module1

    Sub Main()

    Dim int1 = 0, int2 = 1, int3 As Integer

    On Error GoTo Handler

    int3 = int2 / int1

    WriteLine("Program Completed...")

    ReadLine()

    Exit Sub

    Handler:

    If (TypeOf Err.GetException() Is OverflowException) Then

    WriteLine("Overflow Error")

    Resume Next

    End If

    End Sub

    End Module

    Output:

    Overflow Error

    Program Completed

  • GUI Lab Manual 35

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    WINDOWS APPLICATIONS

  • GUI Lab Manual 36

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    To implement all arithmetic operations using buttons

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    Label3.Text = "Result is : " & Val(TextBox1.Text) + Val(TextBox2.Text)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button2.Click

    Label3.Text = "Result is : " & Val(TextBox1.Text) - Val(TextBox2.Text)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button3.Click

    Label3.Text = "Result is : " & Val(TextBox1.Text) * Val(TextBox2.Text)

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button4.Click

    Windows Form Designer generated code

  • GUI Lab Manual 37

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Label3.Text = "Result is : " & Val(TextBox1.Text) \ Val(TextBox2.Text)

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button5.Click

    Label3.Text = "Result is : " & Val(TextBox1.Text) Mod Val(TextBox2.Text)

    End Sub

    End Class

    Output:

  • GUI Lab Manual 38

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    To implement all arithmetic operations using Radio buttons

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton1.CheckedChanged

    Label3.Text = "Result is : " & Val(TextBox1.Text) + Val(TextBox2.Text)

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton2.CheckedChanged

    Label3.Text = "Result is : " & Val(TextBox1.Text) - Val(TextBox2.Text)

    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton3.CheckedChanged

    Label3.Text = "Result is : " & Val(TextBox1.Text) * Val(TextBox2.Text)

    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton4.CheckedChanged

    Windows Form Designer generated code

  • GUI Lab Manual 39

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Label3.Text = "Result is : " & Val(TextBox1.Text) \ Val(TextBox2.Text)

    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton5.CheckedChanged

    Label3.Text = "Result is : " & Val(TextBox1.Text) Mod Val(TextBox2.Text)

    End Sub

    End Class

    Output:

  • GUI Lab Manual 40

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    To demo group box

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton1.CheckedChanged

    Label1.Text = "You Have Clicked Radio Button 1"

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton2.CheckedChanged

    Label1.Text = "You Have Clicked Radio Button 2"

    End Sub

    End Class

    Output:

    Windows Form Designer generated code

  • GUI Lab Manual 41

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    To implement Alarm

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Dim blnAlarm As Boolean = False

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles MyBase.Load

    Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Timer1.Tick

    Label1.Text = Format(Now, "hh:mm:ss")

    If TextBox1.Text "" And TextBox2.Text "" And TextBox3.Text "" Then

    Dim AlarmTime = New DateTime(Today.Year, Today.Month, Today.Day,

    CInt(TextBox1.Text), CInt(TextBox2.Text), CInt(TextBox3.Text))

    If Now > AlarmTime And blnAlarm Then

    Beep()

    End If

    End If

    Windows Form Designer generated code

  • GUI Lab Manual 42

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton1.CheckedChanged

    If RadioButton1.Checked Then

    blnAlarm = True

    End If

    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles RadioButton2.CheckedChanged

    If RadioButton2.Checked Then

    blnAlarm = False

    End If

    End Sub

    End Class

    Output:

  • GUI Lab Manual 43

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    To implement picker

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles MyBase.Load

    DateTimePicker1.Format = DateTimePickerFormat.Custom

    DateTimePicker1.CustomFormat = "dd hh:m:s tt"

    End Sub

    Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As

    System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged

    TextBox1.Text = "Day of the Month selected is " &

    MonthCalendar1.SelectionRange.Start.Day

    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles DateTimePicker1.ValueChanged

    TextBox1.Text = "Date Selected " & DateTimePicker1.Text

    End Sub

    End Class

    Output:

    Windows Form Designer generated code

  • GUI Lab Manual 44

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

  • GUI Lab Manual 45

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT PROGRESS BAR

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Timer1.Tick

    ProgressBar1.Value += 1

    If ProgressBar1.Value = ProgressBar1.Maximum Then

    Timer1.Enabled = False

    End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    Timer1.Enabled = True

    End Sub

    End Class

    Output:

  • GUI Lab Manual 46

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT TRACK BAR

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles TrackBar1.Scroll

    TextBox1.Text = "trackbar value:" & TrackBar1.Value

    End Sub

    End Class

    Output:

  • GUI Lab Manual 47

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT MOUSE TRACKING

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Form1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs)

    Handles MyBase.MouseEnter

    StatusBar1.Text = "Mouse Entered"

    End Sub

    Private Sub Form1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs)

    Handles MyBase.MouseLeave

    StatusBar1.Text = "Mouse Left"

    End Sub

    End Class

    Output:

  • GUI Lab Manual 48

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON THE CHECK BOX

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles CheckBox1.CheckedChanged

    Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, Label1.Font.Style Xor

    FontStyle.Bold)

    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles CheckBox2.CheckedChanged

    Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, Label1.Font.Style Xor

    FontStyle.Italic)

    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles CheckBox3.CheckedChanged

    Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, Label1.Font.Style Xor

    FontStyle.Underline)

    End Sub

    Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles CheckBox4.CheckedChanged

    Label1.Font = New Font(Label1.Font.Name, Label1.Font.Size, Label1.Font.Style Xor

    FontStyle.Strikeout)

    End Sub

  • GUI Lab Manual 49

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Class

    Output:

  • GUI Lab Manual 50

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON THE COMBO BOX FOR GEOMETRIC SHAPES

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e

    As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    Dim myGraphics As Graphics = MyBase.CreateGraphics()

    Dim myPen As New Pen(Color.DarkRed)

    Dim mySolidBrush As New SolidBrush(Color.DarkRed)

    myGraphics.Clear(Color.White)

    Select Case ComboBox1.SelectedIndex

    Case 0

    myGraphics.DrawEllipse(myPen, 50, 50, 150, 150)

    Case 1

    myGraphics.DrawRectangle(myPen, 50, 50, 150, 150)

    Case 2

    myGraphics.DrawEllipse(myPen, 50, 85, 150, 115)

    Case 3

    myGraphics.DrawPie(myPen, 50, 50, 150, 150, 0, 45)

    Case 4

    myGraphics.FillEllipse(mySolidBrush, 50, 50, 150, 150)

    Case 5

    myGraphics.FillRectangle(mySolidBrush, 50, 50, 150, 150)

  • GUI Lab Manual 51

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Case 6

    myGraphics.FillEllipse(mySolidBrush, 50, 85, 150, 115)

    Case 7

    myGraphics.FillPie(mySolidBrush, 50, 50, 150, 150, 0, 45)

    End Select

    End Sub

    End Class

    Output:

  • GUI Lab Manual 52

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON TAB CONTROL FOR GEOMETRIC SHAPES

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Dim g As Graphics

    Dim up, down As Point

    Dim r As Rectangle

    Dim Tool As Tools

    Dim Points() As Point

    Dim NumberPoints As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles MyBase.Load

    g = Me.CreateGraphics()

    End Sub

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As

    System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

    If (ToolBar1.Buttons(0) Is e.Button) Then

    Tool = Tools.Rectangle

    End If

  • GUI Lab Manual 53

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    If (ToolBar1.Buttons(1) Is e.Button) Then

    Tool = Tools.Ellipse

    End If

    If (ToolBar1.Buttons(2) Is e.Button) Then

    Tool = Tools.Line

    End If

    If (ToolBar1.Buttons(3) Is e.Button) Then

    Tool = Tools.Draw

    End If

    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

    down = New Point(e.X, e.Y)

    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

    up = New Point(e.X, e.Y)

    r = New Rectangle(Math.Min(up.X, down.X), Math.Min(up.Y, down.Y), Math.Abs(up.X -

    down.X), Math.Abs(up.Y - down.Y))

  • GUI Lab Manual 54

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Select Case Tool

    Case Tools.Rectangle

    g.DrawRectangle(Pens.BlueViolet, r)

    Case Tools.Ellipse

    g.DrawEllipse(Pens.BlueViolet, r)

    Case Tools.Line

    g.DrawLine(Pens.BlueViolet, up, down)

    End Select

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

    If Tool = Tools.Draw And e.Button = MouseButtons.Left Then

    Dim p As New Point(e.X, e.Y)

    ReDim Preserve Points(NumberPoints)

    Points(NumberPoints) = p

    NumberPoints += 1

    If NumberPoints >= 2 Then

    g.DrawLines(Pens.BlueViolet, Points)

    End If

    End If

  • GUI Lab Manual 55

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As

    System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

    Select Case Tool

    Case Tools.Rectangle

    g.DrawRectangle(Pens.BlueViolet, r)

    Case Tools.Ellipse

    g.DrawEllipse(Pens.BlueViolet, r)

    Case Tools.Line

    g.DrawLine(Pens.BlueViolet, up, down)

    Case Tools.Draw

    If NumberPoints >= 2 Then

    g.DrawLines(Pens.BlueViolet, Points)

    End If

    End Select

    End Sub

    End Class

    Enum Tools

    Rectangle

    Ellipse

    Line

  • GUI Lab Manual 56

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Draw

    End Enum

    Output:

  • GUI Lab Manual 57

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    PROGRAM TO PAINT USING MOUSE

    Public Class FrmPainter

    Inherits System.Windows.Forms.Form

    Dim shouldPaint As Boolean = False

    Private Sub FrmPainter_MouseMove( ByVal sender As System.Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove

    If shouldPaint Then

    Dim graphic As Graphics = CreateGraphics()

    graphic.FillEllipse (New SolidBrush(Color.BlueViolet), e.X, e.Y, 4, 4)

    End If

    End Sub

    Private Sub FrmPainter_MouseDown(ByVal sender As Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

    shouldPaint = True

    End Sub

    Private Sub FrmPainter_MouseUp(ByVal sender As Object, ByVal e As

    System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

    shouldPaint = False

    Windows Form Designer generated code

  • GUI Lab Manual 58

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    Private Sub FrmPainter_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Load

    End Sub

    End Class

    Output:

  • GUI Lab Manual 59

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT STATIC LOGIN

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    If TextBox1.Text = "KITS" And TextBox2.Text = "KITS" Then

    Label2.Text = "Access Granted"

    Else

    Label2.Text = "Access Denied, Please Enter Again"

    TextBox1.Text = ""

    TextBox2.Text = ""

    End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button2.Click

    TextBox1.Text = ""

    TextBox2.Text = ""

    Label2.Text = ""

    End Sub

    Windows Form Designer generated code

  • GUI Lab Manual 60

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Class

    Output:

  • GUI Lab Manual 61

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT NOTEPAD APPLICATION

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles MenuItem6.Click

    RichTextBox1.Text = " "

    End Sub

    Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem7.Click

    If OpenFileDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.LoadFile(OpenFileDialog1.FileName,

    RichTextBoxStreamType.PlainText)

    End If

    End Sub

    Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem8.Click

    If SaveFileDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.SaveFile(SaveFileDialog1.FileName,

    RichTextBoxStreamType.PlainText)

    Windows Form Designer generated code

  • GUI Lab Manual 62

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End If

    End Sub

    Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem9.Click

    If SaveFileDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.SaveFile(SaveFileDialog1.FileName,

    RichTextBoxStreamType.PlainText)

    End If

    End Sub

    Private Sub MenuItem28_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem28.Click

    If FontDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.Font = FontDialog1.Font

    RichTextBox1.ForeColor = FontDialog1.Color

    End If

    End Sub

    Private Sub MenuItem13_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem13.Click

    PrintDialog1.Document = PrintDocument1

  • GUI Lab Manual 63

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    PrintDialog1.PrinterSettings = PrintDocument1.PrinterSettings

    PrintDialog1.AllowSomePages = True

    If PrintDialog1.ShowDialog = DialogResult.OK Then

    PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings

    PrintDocument1.Print()

    End If

    End Sub

    Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem12.Click

    PrintPreviewDialog1.Document = PrintDocument1

    PrintPreviewDialog1.ShowDialog()

    End Sub

    Private Sub MenuItem16_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem16.Click

    RichTextBox1.Undo()

    End Sub

    Private Sub MenuItem18_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem18.Click

    RichTextBox1.Cut()

  • GUI Lab Manual 64

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    Private Sub MenuItem19_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem19.Click

    RichTextBox1.Copy()

    End Sub

    Private Sub MenuItem20_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem20.Click

    RichTextBox1.Paste()

    End Sub

    Private Sub MenuItem21_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem21.Click

    RichTextBox1.Cut()

    End Sub

    Private Sub MenuItem23_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem23.Click

    RichTextBox1.SelectAll()

    End Sub

  • GUI Lab Manual 65

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Private Sub MenuItem25_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem25.Click

    MsgBox("this will help in writing the documents")

    End Sub

    Private Sub MenuItem27_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem27.Click

    MsgBox("hi this is ur notepad")

    End Sub

    Private Sub MenuItem15_Click_1(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem15.Click

    If ColorDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.BackColor = ColorDialog1.Color

    End If

    End Sub

    Private Sub MenuItem24_Click_1(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MenuItem24.Click

    If ColorDialog1.ShowDialog DialogResult.Cancel Then

    RichTextBox1.ForeColor = ColorDialog1.Color

    End If

  • GUI Lab Manual 66

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    End Class

    Output:

  • GUI Lab Manual 67

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO ADD AND DEMO LIST BOX ITEMS

    Public Class FrmListBox

    Inherits System.Windows.Forms.Form

    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles cmdAdd.Click

    lstDisplay.Items.Add(txtInput.Text)

    txtInput.Text = ""

    End Sub

    Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles cmdRemove.Click

    If lstDisplay.SelectedIndex -1 Then

    lstDisplay.Items.RemoveAt(lstDisplay.SelectedIndex)

    End If

    End Sub

    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles cmdClear.Click

    Windows Form Designer generated code

  • GUI Lab Manual 68

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    lstDisplay.Items.Clear()

    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles cmdExit.Click

    Application.Exit()

    End Sub

    End Class

    Output:

  • GUI Lab Manual 69

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO COLOR DIALOGS

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    Dim colorbox As ColorDialog = New ColorDialog

    Dim r As DialogResult

    r = colorbox.ShowDialog()

    If r = DialogResult.Cancel Then

    Return

    End If

    Button1.ForeColor = colorbox.Color

    Button2.ForeColor = colorbox.Color

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button2.Click

    Dim colorbox As ColorDialog = New ColorDialog

    Dim r As DialogResult

    colorbox.FullOpen = True

    Windows Form Designer generated code

  • GUI Lab Manual 70

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    r = colorbox.ShowDialog()

    If r = DialogResult.Cancel Then

    Return

    End If

    Me.BackColor = colorbox.Color

    End Sub

    End Class

    Output:

  • GUI Lab Manual 71

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO SHOW TIME

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Timer1.Tick

    Label1.Text = TimeOfDay

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles MyBase.Load

    Timer1.Enabled = True

    End Sub

    End Class

    Output:

  • GUI Lab Manual 72

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON VALIDATIONS

    Imports System.Text.RegularExpressions

    Public Class FrmValid

    Inherits System.Windows.Forms.Form

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles cmdOK.Click

    If (txtPhone.Text = "" OrElse txtZip.Text = "" OrElse txtState.Text = "" OrElse txtCity.Text

    = "" OrElse txtAddress.Text = "" OrElse txtFirst.Text = "" OrElse txtLast.Text = "") Then

    MessageBox.Show("Please fill in all fields", "Error", MessageBoxButtons.OK,

    MessageBoxIcon.Error)

    txtLast.Focus()

    Return

    End If

    If Not Regex.Match(txtLast.Text, "^[A-Z][a-zA-Z]*$").Success Then

    MessageBox.Show("Invalid Last Name", "Message")

    txtLast.Focus()

    Return

    End If

    If Not Regex.Match(txtFirst.Text, "^[A-Z][a-zA-Z]*$").Success Then

    MessageBox.Show("Invalid First Name", "Message")

    txtFirst.Focus()

    Return

  • GUI Lab Manual 73

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End If

    If Not Regex.Match(txtAddress.Text, "([a-zA-Z]" & "+|[a-zA-Z]+\s[a-zA-Z]+)$").Success

    Then

    MessageBox.Show("Invalid Address", "Message")

    txtAddress.Focus()

    Return

    End If

    If Not Regex.Match(txtCity.Text, "^([a-zA-Z]+|[a-zA-Z]" & "+\s[a-zA-Z]+)$").Success

    Then

    MessageBox.Show("Invalid City", "Message")

    txtCity.Focus()

    Return

    End If

    If Not Regex.Match(txtState.Text, "^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success Then

    MessageBox.Show("Invalid State", "Message")

    txtState.Focus()

    Return

    End If

    If Not Regex.Match(txtZip.Text, "^\d{6}$").Success Then

    MessageBox.Show("Invalid zip code", "Message")

    txtZip.Focus()

    Return

  • GUI Lab Manual 74

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End If

    If Not Regex.Match(txtPhone.Text, "^[0-9]" & "\d{2}-[1-9]\d{2}-\d{4}$").Success Then

    MessageBox.Show("Invalid Phone Number", "Message")

    txtPhone.Focus()

    Return

    End If

    Me.Hide()

    MessageBox.Show("Thank you!", "Information Correct", MessageBoxButtons.OK,

    MessageBoxIcon.Information)

    Application.Exit()

    End Sub

    End Class

    Output:

  • GUI Lab Manual 75

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO SHOW CORRESPONDING CHARACTER

    Public Class FrmButtonTest

    Inherits System.Windows.Forms.Form

    Private Sub cmdShow_Click(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles cmdShow.Click

    lblOutput.Text = txtInput.Text

    End Sub

    End Class

    Output:

    Windows Form Designer generated code

  • GUI Lab Manual 76

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO DEMO ON CALCULATOR

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Dim temp As Double = 0

    Dim opt As Integer = 0

    Dim st As Boolean = False

    Public Sub cal()

    Select Case opt

    Case 1

    TextBox1.Text = temp + Val(TextBox1.Text)

    Case 2

    TextBox1.Text = temp - Val(TextBox1.Text)

    Case 3

    TextBox1.Text = temp * Val(TextBox1.Text)

    Case 4

    TextBox1.Text = temp / Val(TextBox1.Text)

    Case Else

    Windows Form Designer generated code

  • GUI Lab Manual 77

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Select

    End Sub

    'Button 1

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button3.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "1"

    End Sub

    'Button 2

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button7.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "2"

    End Sub

  • GUI Lab Manual 78

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    'Button 3

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button11.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "3"

    End Sub

    'Button 4

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button2.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "4"

    End Sub

    'Button 5

  • GUI Lab Manual 79

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button6.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "5"

    End Sub

    'Button 6

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button10.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "6"

    End Sub

    'Button 7

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

  • GUI Lab Manual 80

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "7"

    End Sub

    'Button 8

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button5.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "8"

    End Sub

    'Button 9

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button9.Click

    If st = True Then

    TextBox1.Text = ""

  • GUI Lab Manual 81

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "9"

    End Sub

    'Button 0

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button4.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "0"

    End Sub

    'Button +

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button13.Click

    If opt = 1 Or opt = 2 Or opt = 3 Or opt = 4 Then

    cal()

    End If

    opt = 1

  • GUI Lab Manual 82

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    st = True

    temp = Val(TextBox1.Text)

    End Sub

    'Button -

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button14.Click

    If opt = 1 Or opt = 2 Or opt = 3 Or opt = 4 Then

    cal()

    End If

    opt = 2

    st = True

    temp = Val(TextBox1.Text)

    End Sub

    'Button *

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button15.Click

    If opt = 1 Or opt = 2 Or opt = 3 Or opt = 4 Then

    cal()

    End If

  • GUI Lab Manual 83

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    opt = 3

    st = True

    temp = Val(TextBox1.Text)

    End Sub

    'Button /

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button16.Click

    If opt = 1 Or opt = 2 Or opt = 3 Or opt = 4 Then

    cal()

    End If

    opt = 4

    st = True

    temp = Val(TextBox1.Text)

    End Sub

    'Button =

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button12.Click

    cal()

    opt = 6

    st = True

    End Sub

  • GUI Lab Manual 84

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    'Button AC

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button17.Click

    TextBox1.Text = ""

    st = False

    temp = 0

    opt = 0

    End Sub

    'Button Del

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button18.Click

    TextBox1.Text = ""

    st = False

    End Sub

    'Button .

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button8.Click

    If st = True Then

    TextBox1.Text = ""

    st = False

    End If

    TextBox1.Text = TextBox1.Text + "."

  • GUI Lab Manual 85

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Sub

    'Button +/-

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button19.Click

    TextBox1.Text = -Val(TextBox1.Text)

    End Sub

    'Button 1/x

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button20.Click

    TextBox1.Text = 1 / Val(TextBox1.Text)

    End Sub

    End Class

    Output:

  • GUI Lab Manual 86

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    INTRODUCTION

    TO

    ADO.NET

  • GUI Lab Manual 87

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    ADO stands for Active X Data Objects

    ADO.NET is a new data handling model that it takes easy to handle data on Internet. At the heart

    of ADO.NET is XML, all data is represented in XML format and exchanged that way.

    Data is handled through ADO.NET, facilitates development of web applications. It is build on

    disconnected data module, uses snapshots of data that are isolated from data source.

    Visual Basic .Net uses ADO.NET as its primary data access and manipulates protocol. These are

    plenty of objects available in ADO.NET

    Most common ADO.NET objects:

    Data connection objects To start working with a database, you must have a data

    connection. A data adapter needs a connection to a data source to read and write data, and

    it uses OleDbConnection or SqlConnection objects to communicate with a data source.

    Data adaptersData adapters are a very important part of ADO.NET. You use them to

    communicate between a data source and a dataset. You typically configure a data adapter

    with SQL to execute against the data source. The two types of data adapters are

    OleDbDataAdapter and SqlDataAdapter objects.

    Command objectsData adapters can read, add, update, and delete records in a data

    source. To allow you to specify how each of these operations work, a data adapter

    contains command objects for each of them. Data adapters support four properties that

    give you access to these command objects: SelectCommand, InsertCommand,

    UpdateCommand, and DeleteCommand.

    DatasetsDatasets store data in a disconnected cache. The structure of a dataset is

    similar to that of a relational database; it gives you access to an object model of tables,

    rows, and columns, and it contains constraints and relationships defined for the dataset.

    Datasets are supported with DataSet objects.

    DataTable objectsDataTable objects hold a data table from a data source. Data tables

    contain two important properties: Columns, which is a collection of the DataColumn

  • GUI Lab Manual 88

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    objects that represent the columns of data in a table, and Rows, which is a collection of

    DataRow objects, representing the rows of data in a table.

    Data readers DataReader objects hold a read-only, forward-only (i.e., you can only

    move from one record to the succeeding record, not backwards) set of data from a

    database. Using a data reader can increase speed because only one row of data is in

    memory at a time.

    Data viewsData views represent a customized view of a single table that can be

    filtered, searched, or sorted. In other words, a data view, supported by the DataView

    class, is a data "snapshot" that takes up few resources.

    Constraint objectsDatasets support constraints to check data integrity. A constraint,

    supported by the Constraint class, is a rule that can be used when rows are inserted,

    updated, or deleted to check the affected table after the operation. There are two types of

    constraints: unique constraints check that the new values in a column are unique

    throughout the table, and foreign-key constraints specify how related records should be

    updated when a record in another table is updated.

    DataRelation objectsDataRelation objects specify a relationship between parent and

    child tables, based on a key that both tables share.

    DataRow objectsDataRow objects correspond to a particular row in a data table. You

    use the Item property to get or set a value in a particular field in the row.

    DataColumn objectsDataColumn objects correspond to the columns in a table. Each

    object has a DataType property that specifies the kind of data each column contains,

    such as integers or string values.

  • GUI Lab Manual 89

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    DATABASE CONNECTION PROGRAMS

  • GUI Lab Manual 90

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO RETRIVE DATA FROM DATABASE USING COSOLE APPLICATION

    Imports System.Data.OleDb

    Imports System.Console

    Module Module1

    Dim cn As OleDbConnection

    Dim cmd As OleDbCommand

    Dim dr As OleDbDataReader

    Sub Main()

    Try

    cn = New OleDbConnection("Data Source=C:\\Documents and Settings\kits\My

    Documents\student.mdb;Provider=Microsoft.Jet.OLEDB.4.0")

    cn.Open()

    cmd = New OleDbCommand("select * from table1", cn)

    dr = cmd.ExecuteReader()

    While (dr.Read())

    WriteLine(dr(0) & " " & dr(1) & " " & dr(2) & " " & dr(3))

    End While

    Catch ex As Exception

    End Try

    dr.Close()

    cn.Close()

  • GUI Lab Manual 91

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    ReadLine()

    End Sub

    End Module

    Output:

    1 guest1 cse kits

    2 guest2 cse kits

    3 guest3 cse kits

  • GUI Lab Manual 92

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO CHECK USERNAME AND PASSWORD FROM THE DATABASE

    Imports System.Data.OleDb

    Public Class Form1

    Inherits System.Windows.Forms.Form

    Dim constring As String

    Dim querystring As String

    Dim olecon As OleDbConnection

    Dim datardr As OleDbDataReader

    Dim olecmd As OleDbCommand

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As

    System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

    Dim form1 As New Registration_Form

    form1.Show()

    Me.Hide()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    constring = "Data Source=C:\\Documents and Settings\NESTHAM\My

    Documents\STUDENT.mdb;Provider=Microsoft.Jet.OLEDB.4.0"

    querystring = "select * from employee"

    olecon = New OleDbConnection(constring)

    olecon.Open()

  • GUI Lab Manual 93

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    olecmd = New OleDbCommand(querystring, olecon)

    datardr = olecmd.ExecuteReader()

    Dim un, pwd As String

    Dim unt, pwdt As String

    Dim vuser As Boolean = False

    un = TextBox1.Text

    pwd = TextBox2.Text

    If datardr.HasRows Then

    While (datardr.Read())

    unt = datardr.GetValue(0)

    pwdt = datardr.GetValue(1)

    If ((unt = un) And (pwdt = pwd)) Then

    vuser = True

    Label3.Text = "correct"

    Dim form1 As New Students_Data

    form1.Show()

    Me.Hide()

    End If

    End While

    End If

    If vuser = False Then

  • GUI Lab Manual 94

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Label3.Text = "in correct"

    End If

    End Sub

    End Class

    Output:

  • GUI Lab Manual 95

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    TO IMPLEMENT INSERTION, UPDATING, DELETING AND VIEW THE DATA

    FROM THE DATABASE

    Imports System.Data.OleDb

    Public Class Registration_Form

    Inherits System.Windows.Forms.Form

    Dim cn As OleDbConnection

    Dim cmd As OleDbCommand

    Dim dr As OleDbDataReader

    Dim i As Integer

    Dim str As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button1.Click

    Try

    cn = New OleDbConnection("Data Source=C:\\Documents and Settings\NESTHAM\My

    Documents\STUDENT.mdb;Provider=Microsoft.Jet.OLEDB.4.0")

    cmd = New OleDb.OleDbCommand("insert into reg values(?,?,?,?,?,?)", cn)

    cmd.Parameters.Add(New OleDb.OleDbParameter("@u_name", TextBox1.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@p_name", TextBox2.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@c_name", TextBox3.Text.Trim))

  • GUI Lab Manual 96

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    cmd.Parameters.Add(New OleDb.OleDbParameter("@year",

    CInt(TextBox4.Text.Trim)))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@course_name",

    TextBox5.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@roll", CInt(TextBox6.Text.Trim)))

    cmd.Connection.Open()

    Dim n As Integer

    n = cmd.ExecuteNonQuery()

    If n = 1 Then

    MessageBox.Show("inserted successfully")

    Else

    MessageBox.Show("insertion failed")

    End If

    cmd.Connection.Close()

    Catch ex As OleDb.OleDbException

    MessageBox.Show(ex.ToString)

    End Try

    cn.Close()

    End Sub

  • GUI Lab Manual 97

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button2.Click

    TextBox1.Text = ""

    TextBox2.Text = ""

    TextBox3.Text = ""

    TextBox4.Text = ""

    TextBox5.Text = ""

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button3.Click

    Dim Registration_Form As New Students_Data

    Registration_Form.Show()

    Me.Hide()

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Handles Button4.Click

    Try

  • GUI Lab Manual 98

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    cmd = New OleDb.OleDbCommand("update reg set

    u_name=?,p_name=?,c_name=?,course_name=?,where year=?", cn)

    cmd.Parameters.Add(New OleDb.OleDbParameter("@roll", CInt(TextBox6.Text.Trim)))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@u_name", TextBox1.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@p_name", TextBox2.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@c_name", TextBox3.Text.Trim))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@year",

    CInt(TextBox3.Text.Trim)))

    cmd.Parameters.Add(New OleDb.OleDbParameter("@course_name",

    TextBox5.Text.Trim))

    cmd.Connection.Open()

    Dim n As Integer

    n = cmd.ExecuteNonQuery()

    If n = 1 Then

    MessageBox.Show("updates successfully")

    Else

    MessageBox.Show("updation failed")

    End If

    cmd.Connection.Close()

    Catch ex As OleDb.OleDbException

    MessageBox.Show(ex.ToString)

  • GUI Lab Manual 99

    B. Raju, Asst. Professor, KITS, Warangal- 506 015

    End Try

    End Sub

    End Class

    Output: