Advertisement
Guest User

Shawn

a guest
Aug 17th, 2008
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 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.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace GaryCalculator
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         List<float> numbers = new List<float>();
  14.        
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Total()
  21.         {
  22.             float answer = 0;
  23.  
  24.             foreach (float number in numbers)
  25.             {
  26.                 answer += number;
  27.             }
  28.             lblOutput.Text = answer.ToString();
  29.             numbers.Clear();
  30.         }
  31.  
  32.         private void Form1_KeyPress(object sender, KeyPressEventArgs e)
  33.         {
  34.             MessageBox.Show(e.KeyChar.ToString());
  35.         }
  36.  
  37.         private void Form1_KeyDown(object sender, KeyEventArgs e)
  38.         {
  39.             if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
  40.             {
  41.                 MessageBox.Show("Enter key");
  42.             }
  43.             if (e.KeyCode == Keys.C)
  44.             {
  45.                 lblOutput.Text = "";
  46.                 numbers.Clear();
  47.             }
  48.             else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0)
  49.                 lblOutput.Text += "0";
  50.             else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1)
  51.                 lblOutput.Text += "1";
  52.             else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2)
  53.                 lblOutput.Text += "2";
  54.             else if (e.KeyCode == Keys.D3 || e.KeyCode == Keys.NumPad3)
  55.                 lblOutput.Text += "3";
  56.             else if (e.KeyCode == Keys.D4 || e.KeyCode == Keys.NumPad4)
  57.                 lblOutput.Text += "4";
  58.             else if (e.KeyCode == Keys.D5 || e.KeyCode == Keys.NumPad5)
  59.                 lblOutput.Text += "5";
  60.             else if (e.KeyCode == Keys.D6 || e.KeyCode == Keys.NumPad6)
  61.                 lblOutput.Text += "6";
  62.             else if (e.KeyCode == Keys.D7 || e.KeyCode == Keys.NumPad7)
  63.                 lblOutput.Text += "7";
  64.             else if (e.KeyCode == Keys.D8 || e.KeyCode == Keys.NumPad8)
  65.                 lblOutput.Text += "8";
  66.             else if (e.KeyCode == Keys.D9 || e.KeyCode == Keys.NumPad9)
  67.                 lblOutput.Text += "9";
  68.             else if (e.KeyCode == Keys.Decimal)
  69.             {
  70.                 if (!lblOutput.Text.Contains("."))
  71.                     lblOutput.Text += ".";
  72.             }
  73.             else if (e.KeyCode == Keys.Add)
  74.             {
  75.                 MessageBox.Show("Add");
  76.             }
  77.             else if (e.KeyCode == Keys.Subtract)
  78.             {
  79.                 MessageBox.Show("Subtract");
  80.             }
  81.         }
  82.  
  83.         private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
  84.         {
  85.             MessageBox.Show(e.KeyCode.ToString());
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement