Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace GaryCalculator
- {
- public partial class Form1 : Form
- {
- List<float> numbers = new List<float>();
- public Form1()
- {
- InitializeComponent();
- }
- private void Total()
- {
- float answer = 0;
- foreach (float number in numbers)
- {
- answer += number;
- }
- lblOutput.Text = answer.ToString();
- numbers.Clear();
- }
- private void Form1_KeyPress(object sender, KeyPressEventArgs e)
- {
- MessageBox.Show(e.KeyChar.ToString());
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
- {
- MessageBox.Show("Enter key");
- }
- if (e.KeyCode == Keys.C)
- {
- lblOutput.Text = "";
- numbers.Clear();
- }
- else if (e.KeyCode == Keys.D0 || e.KeyCode == Keys.NumPad0)
- lblOutput.Text += "0";
- else if (e.KeyCode == Keys.D1 || e.KeyCode == Keys.NumPad1)
- lblOutput.Text += "1";
- else if (e.KeyCode == Keys.D2 || e.KeyCode == Keys.NumPad2)
- lblOutput.Text += "2";
- else if (e.KeyCode == Keys.D3 || e.KeyCode == Keys.NumPad3)
- lblOutput.Text += "3";
- else if (e.KeyCode == Keys.D4 || e.KeyCode == Keys.NumPad4)
- lblOutput.Text += "4";
- else if (e.KeyCode == Keys.D5 || e.KeyCode == Keys.NumPad5)
- lblOutput.Text += "5";
- else if (e.KeyCode == Keys.D6 || e.KeyCode == Keys.NumPad6)
- lblOutput.Text += "6";
- else if (e.KeyCode == Keys.D7 || e.KeyCode == Keys.NumPad7)
- lblOutput.Text += "7";
- else if (e.KeyCode == Keys.D8 || e.KeyCode == Keys.NumPad8)
- lblOutput.Text += "8";
- else if (e.KeyCode == Keys.D9 || e.KeyCode == Keys.NumPad9)
- lblOutput.Text += "9";
- else if (e.KeyCode == Keys.Decimal)
- {
- if (!lblOutput.Text.Contains("."))
- lblOutput.Text += ".";
- }
- else if (e.KeyCode == Keys.Add)
- {
- MessageBox.Show("Add");
- }
- else if (e.KeyCode == Keys.Subtract)
- {
- MessageBox.Show("Subtract");
- }
- }
- private void Form1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
- MessageBox.Show(e.KeyCode.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement