C# ile hesap makinesi yapımını gerçekleştirelim. Gerekli form elemanlarını ve butonları ekledikten sonra kullanışlı bir hesap makinesi oluşturabiliriz. Öncelikle gerekli kütüphaneleri dahil etmeyi unutmayalım ve kodları yazmaya başlayalı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;
Kütüphane ayarlarımız bu şekilde olacak şimdi projenin geri kalan kısmını yazalım.
namespace WindowsFormsApplication19
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double sayi1;
double sayi2;
double sayi3;
char islem;
private void button8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "4";
}
private void button12_Click(object sender, EventArgs e)
{
string deger = textBox1.Text;
textBox1.Text = " ";
sayi1 = Convert.ToInt32(deger);
islem = '+';
}
private void btn_0_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "0";
}
private void btn_1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "1";
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_2_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "2";
}
private void btn_3_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "3";
}
private void btn_5_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "5";
}
private void btn_6_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "6";
}
private void btn1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "7";
}
private void btn_8_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "8";
}
private void btn_9_Click(object sender, EventArgs e)
{
textBox1.Text = textBox1.Text + "9";
}
private void btn_esittir_Click(object sender, EventArgs e)
{
if (sayi2 != null)
{
string deger2 = textBox1.Text;
textBox1.Text = " ";
sayi2 = Convert.ToInt32(deger2);
if (islem == '*')
{
double sonuc = sayi1 * sayi2;
textBox1.Text = sonuc.ToString();
}
if (islem == '+')
{
double sonuc = sayi1 + sayi2;
textBox1.Text = sonuc.ToString();
}
if (islem == '-')
{
double sonuc = sayi1 - sayi2;
textBox1.Text = sonuc.ToString();
}
if (islem == '/')
{
double sonuc = sayi1 / sayi2;
textBox1.Text = sonuc.ToString();
}
}
}
private void btn_carp_Click(object sender, EventArgs e)
{
string deger = textBox1.Text;
textBox1.Text = " ";
sayi1 = Convert.ToInt32(deger);
islem = '*';
}
private void btn_cikar_Click(object sender, EventArgs e)
{
string deger = textBox1.Text;
textBox1.Text = " ";
sayi1 = Convert.ToInt32(deger);
islem = '-';
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = " ";
}
}
}
C# ile uygulamalardan bir tanesini de bu şekilde yapmış olduk. Kullanışlı bir hesap makinesi yapımı ile kendinizi iyi oranda geliştirebilirsiniz. Herkese iyi çalışmalar dilerim.