Jumat, 16 November 2012

Tutorial program 2D


TUTORIAL DAN PENJELASAN LISTING PROGRAM BIDANG 2 DIMENSI

Untuk membuat sebuah program 2 dimensi dapat di lihat dibawah ini:
    1. Pilih “Strat” > “All Program” >Pilih “Microsoft Visual Studio 2010”
    2. Tampil halaman awal “Start Page” Microsoft Visual Studio 2010
    3. Pilih “New Project” untuk membuat aplikasi.
Ø  FORM 1
Form digunakan untuk kita membuat design dari program yang kita buat namun agar program yang kita buat dapat berjalan sesuai dengan yang kita butuhkan maka dibutuhkan perintah-perintah beruba listung di bawah ini:
Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CenterToScreen()

        Me.Text = " Bentuk Dua Dimensi "
        Me.ForeColor = Color.White
        Me.BackColor = Color.White

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
        Me.Hide()

    End Sub
End Class
 

Me.Text = " Bentuk Dua Dimensi "
Untuk menampilkan teks “Bentuk 2 dimensiMe.ForeColor = Color.White                    Untuk menunjukkan jenis warna pada text Me.BackColor = Color.White
Menunjukkan warna background pada form 1 CenterToScreen()= Untuk menampilkan form menjadi ditengah layar ketika di run




Form2.Show()
Me.Hide()
Jika button 1 di klik maka yang akan muncul adalah Form 2, dan Form yang tadi dibuka akan tersembunyi


Berikut tampilan Form1

Berikut toolbox yang digunakan dalam form 1:
No
Komponen
Properties
Keterangan
1
Form 1
Name 
Text
Form 1
Bentuk 2 dimensi
2
Label 1
Name
Text
Label 1
Bentuk-bentuk 2 dimensi
3
Button1
Name
Text
Button1
Mulai mencoba


Ø  FORM2
Pertama di Form 2 buat desain gambar 2 dimensi apa yang kita inginkan  yaitu Persegi, Lingkaran,dan Oval. Gunakan combobox untuk membuat pilihan Bentuk dan Warna yang kita inginkan. Dan desain dengan menggunakan komponen yang ada di toolbox. Yaitu RectangleShape untuk membuat persegi dan OvalShape untuk membuat bentuk lingkaran atau oval.
Berikut Listing untuk menjalankan programnya:
Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ComboBox1.Text = "Persegi" And ComboBox2.Text = "merah" Then
            RectangleShape1.Visible = True
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
        ElseIf ComboBox1.Text = "Persegi" And ComboBox2.Text = "hijau" Then
            RectangleShape1.Visible = False
            RectangleShape2.Visible = True
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
        ElseIf ComboBox1.Text = "Persegi" And ComboBox2.Text = "ungu" Then
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = True
            RectangleShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
        ElseIf ComboBox1.Text = "Persegi" And ComboBox2.Text = "orange" Then
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = True
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
        ElseIf ComboBox1.Text = "Lingkaran" And ComboBox2.Text = "orange" Then
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = True
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Lingkaran" And ComboBox2.Text = "ungu" Then
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = True
            OvalShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Lingkaran" And ComboBox2.Text = "hijau" Then
            OvalShape1.Visible = False
            OvalShape2.Visible = True
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Lingkaran" And ComboBox2.Text = "merah" Then
            OvalShape1.Visible = True
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Oval" And ComboBox2.Text = "merah" Then
            OvalShape5.Visible = True
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Oval" And ComboBox2.Text = "hijau" Then
            OvalShape5.Visible = False
            OvalShape6.Visible = True
            OvalShape7.Visible = False
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Oval" And ComboBox2.Text = "ungu" Then
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = True
            OvalShape8.Visible = False
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
        ElseIf ComboBox1.Text = "Oval" And ComboBox2.Text = "orange" Then
            OvalShape5.Visible = False
            OvalShape6.Visible = False
            OvalShape7.Visible = False
            OvalShape8.Visible = True
            OvalShape1.Visible = False
            OvalShape2.Visible = False
            OvalShape3.Visible = False
            OvalShape4.Visible = False
            RectangleShape1.Visible = False
            RectangleShape2.Visible = False
            RectangleShape3.Visible = False
            RectangleShape4.Visible = False
 

        End If
    End Sub



Jika Button 1 diklik dalam keadaan jika ComboBox1 diisi ( “Persegi” atau “Lingkaran” atau “Oval”) dan ComboBox2  diisi (“Merah” atau “Hijau” atau “Ungu” atau “Orange”) maka akan  muncul bentuk dan warna yang sesuai dengan yang kita pilih. Ini adalah pengaruh dari rumus dalam listing dan properties dari RectangleShape dan OvalShape. Listing diatas menunjukkan Jika kita memilih oval di combobox1 dan memilih warna orange di combobox2 maka apabila kit klik button 1 yang muncul harus oval dengan warna orange. Dipropertis ditunjukkan bahwa keadaan behavior yaitu “visible’=false. Dan keadaan yang lain ditukis visible”=true untuk memunculkan keaadan yang diinginkan


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        ComboBox1.Text = "Bentuk"
        ComboBox2.Text = "Warna"
        OvalShape5.Visible = False
        OvalShape6.Visible = False
        OvalShape7.Visible = False
        OvalShape8.Visible = False
        OvalShape1.Visible = False
        OvalShape2.Visible = False
        OvalShape3.Visible = False
        OvalShape4.Visible = False
        RectangleShape1.Visible = False
        RectangleShape2.Visible = False
        RectangleShape3.Visible = False
        RectangleShape4.Visible = False
 

End Sub

Listing diatas digunakan Apabila kita mengklik button2  maka semua perintah untuk memunculkan gambar akan hilang artinya semua gambar rectangleshape  atau ovalshape  terhapus dan tidak tampil lagi dilayar.






Berikut desain form 2
Add caption


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 

    End Sub


                Listing ini digunakan untuk menentukan kondisi dari beberapa pilihan di combobox1, pilihan yang ada adalah persegi, lingkaran,dan oval


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        MsgBox("Terimakasih Sudah Menggunakan Program Kami!")
        Start.Close()
End Sub


Jika kita klik button 3 maka akan keluar messagebox “terimakasih sudah menggunakan program kami!”    Start.Close() Listing Untuk menutup program

Berikut tampilannya:
j.JPG

Komponen toolbox yang digunakan diantaranya :
No
Komponen
Properties
Keterangan
1
Form 1
Name 
Text
Form 1
Bentuk-bentuk 2D
2
Label 3
Name
Text
Label 3
Tebak bentuk warna
3
Picturebox1
Name
Text
Picturebox1
4
Label1
Name
Text
Label1
Bentuk
5
Label2
Name
Text
Label2
Warna
6
Combobox2
Name
Text
Combobox2
7
Rectangleshape1
Name
Text
Rectangleshape1
8
Rectangleshape2
Name
Text
Rectangleshape2
9
Rectangleshape3
Name
Text
Rectangleshape3
10
Rectangleshape4
Name
Text
Rectangleshape4
11
Ovalshape1
Name
Text
Ovalshape1
12
Ovalshape2
Name
Text
Ovalshape2
13
Ovalshape3
Name
Text
Ovalshape3
14
Ovalshape4
Name
Text
Ovalshape4
15
Ovalshape5
Name
Text
Ovalshape5
16
Ovalshape6
Name
Text
Ovalshape6
17
Ovalshape7
Name
Text
Ovalshape7
18
Ovalshape8
Name
Text
Ovalshape8
19
Button1
Name
Text
Button1
Mulai
20
Button2
Name
Text
Button2
Reset
21
Button3
Name
Text
Button3
Selesai

Tidak ada komentar:

Posting Komentar