Advertisement
Guest User

kalkulator

a guest
Mar 1st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Kalkulator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         string LiczbaPierwsza, Liczbadruga, Copy, a;
  21.         char RodzajDzialania = ' ';
  22.  
  23.         private void reset()
  24.         {
  25.             t_box_wynik.Clear();
  26.             LiczbaPierwsza = "";
  27.             Liczbadruga = "";
  28.         }
  29.  
  30.         private void btn_dodawanie_Click(object sender, EventArgs e)
  31.         {
  32.             RodzajDzialania = '+';
  33.             t_box_wynik.Text = "";
  34.         }
  35.  
  36.         private void btn_odejmowanie_Click(object sender, EventArgs e)
  37.         {
  38.             RodzajDzialania = '-';
  39.             t_box_wynik.Text = "";
  40.         }
  41.  
  42.         private void btn_mnożenie_Click(object sender, EventArgs e)
  43.         {
  44.             RodzajDzialania = '*';
  45.             t_box_wynik.Text = "";
  46.         }
  47.  
  48.         private void btn_dzielenie_Click(object sender, EventArgs e)
  49.         {
  50.             RodzajDzialania = '/';
  51.             t_box_wynik.Text = "";
  52.         }
  53.  
  54.         private void btn_1_Click(object sender, EventArgs e)
  55.         {
  56.             Dzialanie(1);
  57.         }
  58.  
  59.         private void btn_2_Click(object sender, EventArgs e)
  60.         {
  61.             Dzialanie(2);
  62.         }
  63.  
  64.         private void btn_3_Click(object sender, EventArgs e)
  65.         {
  66.             Dzialanie(3);
  67.         }
  68.  
  69.         private void btn_4_Click(object sender, EventArgs e)
  70.         {
  71.             Dzialanie(4);
  72.         }
  73.  
  74.         private void btn_5_Click(object sender, EventArgs e)
  75.         {
  76.             Dzialanie(5);
  77.         }
  78.  
  79.         private void btn_6_Click(object sender, EventArgs e)
  80.         {
  81.             Dzialanie(6);
  82.         }
  83.  
  84.         private void btn_7_Click(object sender, EventArgs e)
  85.         {
  86.             Dzialanie(7);
  87.         }
  88.  
  89.         private void btn_8_Click(object sender, EventArgs e)
  90.         {
  91.             Dzialanie(8);
  92.         }
  93.  
  94.         private void btn_9_Click(object sender, EventArgs e)
  95.         {
  96.             Dzialanie(9);
  97.         }
  98.  
  99.         private void btn_0_Click(object sender, EventArgs e)
  100.         {
  101.             Dzialanie(0);
  102.         }
  103.  
  104.         private void btn_reset_Click(object sender, EventArgs e)
  105.         {
  106.             reset();
  107.             /*/t_box_wynik.Clear(); //takie coś czyści wszystko ale nie usuwa
  108.             LiczbaPierwsza = "";
  109.             Liczbadruga = "";/*/  
  110.         }
  111.  
  112.         private void btn_przecinek_Click(object sender, EventArgs e)
  113.         {
  114.             MessageBox.Show("Nii działa xD", "Informacja dotycząca przecinka", MessageBoxButtons.OK, MessageBoxIcon.Information);
  115.         }
  116.       private void btn_wynik_Click(object sender, EventArgs e)
  117.         {
  118.             switch (RodzajDzialania)
  119.             {
  120.                 case ('+'):
  121.                     t_box_wynik.Text = (double.Parse(LiczbaPierwsza) + double.Parse(Liczbadruga)).ToString();
  122.                     break;
  123.                 case ('-'):
  124.                     t_box_wynik.Text = (double.Parse(LiczbaPierwsza) - double.Parse(Liczbadruga)).ToString();
  125.                     break;
  126.                 case ('*'):
  127.                     t_box_wynik.Text = (double.Parse(LiczbaPierwsza) * double.Parse(Liczbadruga)).ToString();
  128.                     break;
  129.                 case ('/'):
  130.                     t_box_wynik.Text = (double.Parse(LiczbaPierwsza) / double.Parse(Liczbadruga)).ToString();
  131.                     break;
  132.             }
  133.             LiczbaPierwsza = "";
  134.             Liczbadruga = "";
  135.             RodzajDzialania = ' ';
  136.            
  137.             LiczbaPierwsza = t_box_wynik.Text;
  138.             {
  139.                 Liczbadruga = "";
  140.             }
  141.         }
  142.  
  143.         private void btn_zmiana_znaku_Click(object sender, EventArgs e)
  144.         {
  145.             a = t_box_wynik.Text;
  146.             Convert.ToInt64(a);
  147.             a = a * -1;
  148.             Convert.ToString(a);
  149.             t_box_wynik.Text = a;
  150.         }
  151.  
  152.         private void btn_Copy_Click(object sender, EventArgs e)
  153.         {
  154.             Copy = t_box_wynik.Text;
  155.             t_box_2.Text = Copy;    // + ('+'.ToString())
  156.             reset();
  157.         }
  158.         private void Dzialanie(double liczba)
  159.         {
  160.             if (RodzajDzialania == ' ')
  161.             {
  162.                 LiczbaPierwsza += liczba;
  163.                 t_box_wynik.Text = LiczbaPierwsza;
  164.             }
  165.             else
  166.             {
  167.                 Liczbadruga += liczba;
  168.                 t_box_wynik.Text = Liczbadruga;
  169.             }
  170.            
  171.         }
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement