27 Ekim 2015 Salı

C# Hesap Makinesi Yapımı





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();
        }

        private void butonlar_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            textBox1.Text += btn.Text;
         //Rakamların olduğu Butonları Tek Tek Seçip Click Eventini Açıyoruz..
        }

        private void button11_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text.Length != 0)
                {
                    textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
                }
            }
            catch
            { }
        }
        double s1,s2;
        string isaret;
        private void oprtrButon_Click(object sender, EventArgs e)
        {
            //+,-,*,/,= ve % olan Butonları Tek Tek Seçip Click Eventini Açıyoruz..
            Button btn = (Button)sender;
            if (btn.Text == "+")
            {
                double.TryParse(textBox1.Text, out s1);
                isaret = btn.Text;
                textBox1.Clear();

            }
            else if (btn.Text == "-")
            {
                double.TryParse(textBox1.Text, out s1);
                isaret = btn.Text;
                textBox1.Clear();

            }
            else if (btn.Text == "/")
            {
                double.TryParse(textBox1.Text, out s1);
                isaret = btn.Text;
                textBox1.Clear();

            }
            else if (btn.Text == "*")
            {
                double.TryParse(textBox1.Text, out s1);
                isaret = btn.Text;
                textBox1.Clear();

            }
            else if (btn.Text == "%")
            {
                double.TryParse(textBox1.Text, out s1);
                isaret = btn.Text;
                textBox1.Clear();

            }
            if (btn.Text == "=")
            {
                double.TryParse(textBox1.Text, out s2);
                if (isaret == "+") textBox1.Text = (s1 + s2).ToString();
                if (isaret == "-") textBox1.Text = (s1 - s2).ToString();
                if (isaret == "*") textBox1.Text = (s1 * s2).ToString();
                if (isaret == "/") textBox1.Text = (s1 / s2).ToString();
                if (isaret == "%") textBox1.Text = (s1 % s2).ToString();
            }
        }

    }
}

Paylaş:

0 yorum:

Yorum Gönder

Popüler

Son

Kategoriler