Minggu, 02 Desember 2012

Windows Form Hitung Luas dan Keliling



Contoh Program Hitung Luas dan Keliling dalam Windows Form Application menggunakan Microsoft Visual Studio 2010

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmHitung : Form
    {
        String pilih;
        Decimal hasil;
        public frmHitung()
        {
            InitializeComponent();
        }

        private void frmHitung_Load(object sender, EventArgs e)
        {
        }
        private void rdLuas_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdLuas.Checked == true)
            {
                rdKeliling.Checked = false;
                pilih = "Luas";
            }
        }

        private void rdKeliling_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdKeliling.Checked == true)
            {
                rdLuas.Checked = false;
                pilih = "Keliling";
            }
        }

        private void cmdBatal_Click(object sender, EventArgs e)
        {
            txtPanjang.Clear();
            txtLebar.Clear();
            rdLuas.Checked = false;
            rdKeliling.Checked = false;
            txtPanjang.Focus();
        }

        private void cmdProses_Click(object sender, EventArgs e)
        {
            Decimal panjang, lebar;
            panjang = Decimal.Parse(this.txtPanjang.Text);
            lebar = Decimal.Parse(this.txtLebar.Text);

            if (pilih == "Luas")
            {
                hasil = panjang * lebar;
            }
            else if (pilih == "Keliling")
            {
                hasil = ((2 * panjang) + (2 * lebar));
            }
            MessageBox.Show("jadi" + pilih + "persegi panjang adalah" + hasil, "informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}



Hasil Coding dari contoh diatas adalah :

 

Tidak ada komentar:

Posting Komentar