Sabtu, 10 November 2012

Tugas 4


LATIHAN CHECKBOX



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim control As Windows.Forms.CheckBox
        TextBox1.Text = ""
        For Each control In Me.GroupBox1.Controls
            If control.Checked = True Then
                TextBox1.Text &= control.Text & ","

            End If
        Next
        TextBox1.Text = Microsoft.VisualBasic.Left(TextBox1.Text, Len(TextBox1.Text) - 1)
    End Sub

    Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged
        Dim control As Windows.Forms.CheckBox
        TextBox1.Text = ""

    End Sub
End Class

Setelah di Run atau dijalankan hasilnya sebagai berikut

















Jika dipilih beberapa akan sebagai berikut

















RADIOBUTTON


Public Class Form1

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        TextBox1.Text = ""
        If RadioButton1.Checked = True Then
        Else
            TextBox1.Text &= "Suami"
        End If
        If RadioButton2.Checked = True Then
        Else
            TextBox1.Text &= "Istri"
        End If
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        TextBox1.Text = ""
        If RadioButton1.Checked = True Then
        Else
            TextBox1.Text &= ""
        End If
        If RadioButton2.Checked = True Then
        Else
            TextBox1.Text &= ""
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class

Dan hasilnya sebagai berikut

Jika diklik pria dan kawin, maka hasilnya sebagai berikut


















Jika diklik wanita dan kawin, maka hasilnya sebagai berikut


















LISTBOX



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim control As Windows.Forms.ListBox
        TextBox1.Text = TextBox1.Text
        TextBox1.Text = ListBox1.Items.Add(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For bil = 1 To 10
            ListBox1.Items.Add(bil)
        Next

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        ListBox1.Text = ListBox2.Items.Add(ListBox1.Text)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ListBox1.SelectionMode = SelectionMode.MultiExtended
        Dim i, j As Integer
        j = ListBox1.Items.Count
        For i = 0 To j - 1
            Try
                ListBox2.Items.Add(ListBox1.Items(ListBox1.SelectedIndices(i)))
            Catch ex As Exception
                j -= 1
            End Try
        Next

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ListBox1.SelectionMode = SelectionMode.MultiExtended

        Dim Jumlah As Integer = ListBox1.Items.Count
        For i = 0 To Jumlah - 1
            ListBox2.Items.Add(ListBox1.Items(i))
        Next

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ListBox2.SelectionMode = SelectionMode.One

        ListBox2.Items.Remove(ListBox2.SelectedItem)

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        ListBox2.SelectionMode = SelectionMode.MultiExtended
        Dim i, j As Integer
        j = ListBox2.Items.Count
        For i = 0 To j - 1
            Try
                ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
            Catch ex As Exception
                j -= 1
            End Try
        Next

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        ListBox2.Items.Clear()
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        Me.Close()
    End Sub
End Class

Hasilnya sebagai berikut


Jika ditekan tombol Satu hasilnya sebagai berikut














Jika ditekan tombol Beberapa akan seperti berikut













Jika ditekan tombol Semua akan seperti berikut













Jika ditekan tombol Hapus Satu akan seperti berikut














Jika ditekan Hapus Beberapa akan seperti berikut













Jika ditekan Hapus Semua akan seperti berikut














Untuk mendapatkan file download file

Maaf jika masih banyak kekurangan :)

Tidak ada komentar:

Posting Komentar