Cara membuat Kalkulator Sederhana

Pertama , buka Visual Studio 2010
Pilih New Project , Pilih Windows Form Application
Masukkan nama Applikasinya , misalnya "Kalkulator Sederhana"


Karena App Kalkulator Sederhananya membutuhkan 4 form , maka kita buat formnya dulu
Selanjutnya Klik kanan di "Kalkulator Sederhana" yang terletak di menu Solution Explorer
Pilih Add , New item atau Pilih add, Windows Form
Kalo sobat mau lebih simple , bisa tekan CTRL + SHIFT + A 




Kalau sudah , pilih Windows Form , terus masukkan click add



 Jika sudah , maka ulangi langkah sampai ke-4 form terbuat



Sekarang kita buat tampilannya , pilih radiobutton , textbox , checkbox , dan button di menu toolbox


kita buat dengan tampilan seperti ini 


Setelah itu , kita ubah textnya , 
liat di menu Properties , pilih text dan tulis Operator



Trus kita ubah nama Radiobutton1 menjadi “op”
Di Properties paling atas , di bagian “(name)” kita ubah namanya disitu



Jika sudah maka buatlah desain ke-4 form seperti dibawah ini
Form 2

Form 3
Untuk textbox1 dan textbox2, textbox3 , sobat ubah namanya menjadi angka1, angka2, dan hasil

Form 4 , untuk membuat tulisan NILAI maka pilih label di Toolbox ,
dan kita buat label tanpa teks untuk nilai akhirnya nanti diantara “Nilai” dan “…….”

untuk mengatur fontnya , bisa di atur sendiri di pilihan font di menu properties


Selanjutnya kita masukkan kode , kita mulai dari form 1
Klik form1 2x , trus ada muncul blablablabla , tinggal di copas di bawah ini dong

Public Class Form1
    Private Sub op_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles op.CheckedChanged
        If op.Checked = True Then
            TextBox1.Text = "OPERATOR"
            CheckBox1.Checked = True
        End If
    End Sub





    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then
            MsgBox("click operator untuk melanjutkan")

        Else
            Form2.Show()
            Me.Hide()
        End If
    End Sub
End Class

Form 2

Public Class Form2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("Pilih perintahnya")
    End Sub
    Private Sub RadioButton1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadioButton1.MouseClick
        Form3.Show()
        Me.Hide()
        Form3.Label1.Text = "+"
    End Sub
    Private Sub RadioButton2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadioButton2.MouseClick
        Form3.Show()
        Me.Hide()
        Form3.Label1.Text = "-"
    End Sub
    Private Sub RadioButton3_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadioButton3.MouseClick
        Form3.Show()
        Me.Hide()
        Form3.Label1.Text = "x"
    End Sub
    Private Sub RadioButton4_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RadioButton4.MouseClick
        Form3.Show()
        Me.Hide()
        Form3.Label1.Text = "/"
    End Sub
End Class


Form 3

Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("Masukkan angka yang ingin dihitung")
        If Form2.RadioButton1.Checked = True Then
            Label1.Text = "+"
            Hasil.Text = Val(angka1.Text) + Val(angak2.Text)
        ElseIf Form2.RadioButton2.Checked = True Then
            Label1.Text = "-"
            Hasil.Text = Val(angka1.Text) + Val(angak2.Text)
        ElseIf Form2.RadioButton3.Checked = True Then
            Label1.Text = "x"
            Hasil.Text = Val(angka1.Text) + Val(angak2.Text)
        ElseIf Form2.RadioButton4.Checked = True Then
            Label1.Text = "/"
            Hasil.Text = Val(angka1.Text) + Val(angak2.Text)
        End If
    End Sub
    Private Sub angak2_3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles angak2_3.KeyPress
        If e.KeyChar = Chr(13) Then
            Button1.PerformClick()
            Form4.Show()
            Me.Hide()
        End If
    End Sub
    Private Sub Button1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseClick
        Form4.Show()
        Me.Hide()
    End Sub
End Class

Form 4

Public Class Form4
    Private Sub akhir_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Form2.RadioButton1.Checked = True Then
            Label3.Text = Val(Form3.angka1.Text) + Val(Form3.angak2.Text)
        ElseIf Form2.RadioButton2.Checked = True Then
            Label3.Text = Val(Form3.angka1.Text) - Val(Form3.angak2.Text)
        ElseIf Form2.RadioButton3.Checked = True Then
            Label3.Text = Val(Form3.angka1.Text) * Val(Form3.angak2.Text)
        ElseIf Form2.RadioButton4.Checked = True Then
            Label3.Text = Val(Form3.angka1.Text) - Val(Form3.angak2.Text)
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form1.Close()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.Show()
        Me.Hide()
    End Sub
End Class


Terima kasih atas perhatian sobat, maaf ya kalo ada kesalahan
Jika tidak bisa gagal debugging maka comment yaa , saya akan perbaiki kesalahannya


Share This!


Powered By Blogger · Designed By Seo Blogger Templates