İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

C#?ta hesap makinesi yapmak

fatihcan92

0
İyinet Üyesi
Katılım
28 Ocak 2013
Mesajlar
18
Reaction score
0
Bu yazımızda hesap makinesi yaptık bildiğiniz üzere az kod ile de yapılabilirdi ancak bu hesap makinesi hemen hemen windows?un basit hesap makinesi ile aynıdır sadece 4 işlem için kullanabiliriz.

Kodlar:
Kod:
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 hesap_makinesi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        float i = 0;
        int j = 0;
        int hesap = 0;
        String islem = "";
        int a;
 
        private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
        {
 
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //Bir tane sayı butonunu açıklayacağım diğerleri aynısı zaten
            /* j=1 ise yapmışız çünki engellemek istediğimiz sayı girilmeden birden
             * fazla işlem butonlarına tıklandığında yeniden işlem yapmasın yeni
             * sayı girmemizi beklesin. Bunu nasıl sağladık ?
             * yeni sayı girdiğimizde j=0 oluyor o zaman işlem koduna dedik ki 
             * eğer j=0 ise işlem yap.
             */
            if (j == 1) {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "1"; // yazı kutusuna gerekli rakam eklendi
            hesap = 0; /* Bu değişkeni de = (eşitir) i kullanmak için yaptık
            *eşittir ne zaman kullanılır ? önce bir sayı girilir sonra 4 işlemden 
             *birine tıklanır ve tekrar sayı girilir yani en son sayı girildi ise
             *eşittir kullanılır sonuç olarak hesap==0 ise en son sayı girişmiştir.
            */
 
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "2";
            hesap = 0;
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "3";
            hesap = 0;
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "4";
            hesap = 0;
        }
 
        private void button5_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "5";
            hesap = 0;
        }
 
        private void button6_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "6";
            hesap = 0;
        }
 
        private void button7_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "7";
            hesap = 0;
        }
 
        private void button8_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "8";
            hesap = 0;
        }
 
        private void button9_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "9";
            hesap = 0;
        }
 
        private void button10_Click(object sender, EventArgs e)
        {
            if (j == 1)
            {
                textBox1.Text = "";
                j = 0;
            }
            textBox1.Text = textBox1.Text + "0";
            hesap = 0;
        }
 
        private void button12_Click(object sender, EventArgs e)
        {
            if (hesap == 0) { //hesap=0 ise en son sayı girilmiştir. yani 2 kez yada daha fazla 4 işlemden birine tıklar isek sadece ilgini işleme koyar
            i = i + Convert.ToInt64(textBox1.Text);  //son sayı + yeni girdiğiniz sayı = son sayi işlemidir
            textBox1.Text = i.ToString();
            j = 1; // en son dört işlem yaptığımızı j=1 ile belirttik
            hesap = 1; // eşittiri kullanamayız
            islem = "+"; // en son yapılan dört işlemi belirttik
            }
 
        }
 
        private void button13_Click(object sender, EventArgs e)
        {
            if (hesap == 0)
            {
                i = i / Convert.ToInt64(textBox1.Text);
                textBox1.Text = i.ToString();
                j = 1;
                hesap = 1;
                islem = "/";
            }
        }
 
        private void button14_Click(object sender, EventArgs e)
        {
            if (hesap == 0)
            {
                i = i * Convert.ToInt64(textBox1.Text);
                textBox1.Text = i.ToString();
                j = 1;
                hesap = 1;
                islem = "*";
            }
        }
 
        private void button11_Click(object sender, EventArgs e)
        {
            if (hesap == 0)
            {
                i = i - Convert.ToInt64(textBox1.Text);
                textBox1.Text = i.ToString();
                j = 1;
                hesap = 1;
                islem = "-";
            }
        }
 
        private void button15_Click(object sender, EventArgs e)
        {
            if (hesap == 0) { // eşittir i en son sayı girdik ise en son yapılan dört işleme göre olaylar çağırdık
                if (islem == "+") {
                    button12_Click(lisanssız,lisanssız);
                }
                if (islem == "-")
                {
                    button11_Click(lisanssız, lisanssız);
                }
                if (islem == "*")
                {
                    button14_Click(lisanssız, lisanssız);
                }
                if (islem == "/")
                {
                    button13_Click(lisanssız, lisanssız);
                }
            }
        }
 
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //klavyeden yazı girilmesini engelledik ancak kopyala yapıştır ile eklenebilir çünki keypress olayına yazdık sadece
            if (char.IsDigit(e.KeyChar) == false && char.IsControl(e.KeyChar) == false)
            {
                e.Handled = true;
            }
        }
 
    }
}

Kaynak: http://www.tekno-logy.com/cta-hesap-makinesi-yapmak.html
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Backlink ve Tanıtım Yazısı için iletişime geçmek için Skype Adresimiz: .cid.1580508955483fe5

Üst