15 Kasım 2013 Cuma

C# Modern Hesap Makinesi Yapımı




Csharp ile Modern Hesap Makinesi yapımı

KODLAR:

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

namespace Modern_Hesap_Makinesi
{
    public partial class Modern_Hesap_Makinesi : Form
    {
        decimal birinciSayi, ikinciSayi, hafiza;

        string islem;

        Boolean sonuclandi;


        public Modern_Hesap_Makinesi()
        {
            InitializeComponent();
        }

        private void Modern_Hesap_Makinesi_Load(object sender, System.EventArgs e)
        {
            this.Text = "Hesap Makinesi";

            txtSonuc.Text = "";

            this.CancelButton = btnKapat;
        }

        private void rakamlar(object sender, System.EventArgs e)
        {
            if (sonuclandi)
                txtSonuc.Text = (sender as Button).Text;
            else
            {
                txtSonuc.Text = txtSonuc.Text + (sender as Button).Text;
            }
            sonuclandi = false;
        }

        private void btnArtiEksi_Click(object sender, System.EventArgs e)
        {
            if (txtSonuc.Text.Length > 0)

                if (txtSonuc.Text.Substring(0, 1) == "-")

                    //Sayinin basinda - varsa sil

                    txtSonuc.Text = txtSonuc.Text.Substring(1);

                else
                    //- yoksa - ekle
                    txtSonuc.Text = "-" + txtSonuc.Text.Substring(0);
        }

        private void btnVirgul_Click(object sender, System.EventArgs e)
        {
            //sayida virgul yoksa

            if (txtSonuc.Text.IndexOf(",") <= 0)

                if (txtSonuc.Text.Length == 0)

                    //hiç karakter yoksa 0, ekle

                    txtSonuc.Text = "0,";

                else

                    //sayi varsa sonuna virgul ekle
                    txtSonuc.Text = txtSonuc.Text + ",";
        }

        private void btnSil_Click(object sender, System.EventArgs e)
        {
            txtSonuc.Text = "";
        }

        private void btnGeriSil_Click(object sender, System.EventArgs e)
        {
            if (txtSonuc.Text.Length > 0)
            {
                txtSonuc.Text = txtSonuc.Text.Substring(0, txtSonuc.Text.Length - 1);
            }
        }

        private void hafiza_islemleri(object sender, System.EventArgs e)
        {
            if (txtSonuc.Text.Length == 0)
            {
                txtSonuc.Text = "0";
            }

            switch ((sender as Button).Text)
            {
                case "MC":

                    hafiza = 0;
                    break;
                case "M+":

                    hafiza = hafiza + decimal.Parse(txtSonuc.Text);
                    break;
                case "M-":

                    hafiza = hafiza - decimal.Parse(txtSonuc.Text);
                    break;
                case "MR":

                    txtSonuc.Text = hafiza.ToString();
                    break;
            }
        }

        private void Dört_islem(object sender, System.EventArgs e)
        {
            islem = (sender as Button).Text;

            if (txtSonuc.Text.Length == 0)
            {
                txtSonuc.Text = "0";
            }

            birinciSayi = decimal.Parse(txtSonuc.Text);

            sonuclandi = true;
        }

        private void Button_Esit_Click(object sender, System.EventArgs e)
        {
            if (txtSonuc.Text.Length == 0)
            {
                txtSonuc.Text = "0";
            }

            decimal sonuc = 0;

            ikinciSayi = decimal.Parse(txtSonuc.Text);

            switch (islem)
            {
                case "+":

                    sonuc = birinciSayi + ikinciSayi;
                    break;
                case "-":

                    sonuc = birinciSayi - ikinciSayi;
                    break;
                case "*":

                    sonuc = birinciSayi * ikinciSayi;
                    break;
                case "/":

                    if (ikinciSayi == 0)
                        return;
                    sonuc = birinciSayi / ikinciSayi;
                    break;
            }

            sonuclandi = true;

            txtSonuc.Text = sonuc.ToString();

            birinciSayi = sonuc;
        }

        private void islem_Yap_2(object sender, System.EventArgs e)
        {
            decimal sayi;

            if (txtSonuc.Text.Length == 0)

                txtSonuc.Text = "0";


            sayi = decimal.Parse(txtSonuc.Text);

            switch ((sender as Button).Text)
            {
                case "Kök":

                    if (sayi >= 0)
                        txtSonuc.Text = Math.Sqrt((double)sayi).ToString();
                    break;
                case "x²":

                    txtSonuc.Text = (sayi * sayi).ToString();
                    break;
                case "1/x":

                    if (sayi != 0)
                        txtSonuc.Text = (1 / sayi).ToString();
                    break;
            }
        }

        private void kapat_Click(object sender, EventArgs e)
        {
            //Programı Kapat
            this.Close();
        }
    }
}




UYGULAMAYI INDIR

http://www.csharpuygulamalar.com'a teşekkürler

0 yorum:

Yorum Gönder