TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Adam Hearst
NA
7
645
Key Presses in a calculator. Please Read
Nov 10 2018 4:46 PM
I am wondering if there is a way to add to in winforms so when a key is pressed it inputs, In my case I have made a simple calculatour but I would like to make it where you dont need to press the buttons but instead you just click the number on the keyboard and it inputs it.
Below is my code and a picture of my calculator
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
namespace
myCalculator
{
public
partial
class
Calcualtor : Form
{
public
Calcualtor()
{
InitializeComponent();
}
private
void
ZERO_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"0"
;
}
private
void
ONE_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"1"
;
}
private
void
TWO_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"2"
;
}
private
void
THREE_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"3"
;
}
private
void
FOUR_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"4"
;
}
private
void
FIVE_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"5"
;
}
private
void
SIX_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"6"
;
}
private
void
SEVEN_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"7"
;
}
private
void
EIGHT_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"8"
;
}
private
void
NINE_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"9"
;
}
private
void
DIVIDE_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
" / "
;
}
private
void
MULTIPLY_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
" * "
;
}
private
void
SUBTRACT_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
" - "
;
}
private
void
ADD_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
" + "
;
}
private
void
EQUAL_Click(
object
sender, EventArgs e)
{
string
command =
""
;
double
answer = 0;
double
num = 0;
string
[] calculation = INPUT.Text.Split(
' '
);
if
(
double
.TryParse(calculation[0],
out
answer))
{
}
foreach
(var item
in
calculation)
{
if
(
double
.TryParse(item,
out
num))
{
switch
(command)
{
case
"+"
:
answer += num;
break
;
case
"-"
:
answer -= num;
break
;
case
"/"
:
answer /= num;
break
;
case
"*"
:
answer *= num;
break
;
}
}
else
command = item;
}
ANSWER.Text = answer.ToString();
}
private
void
C_Click(
object
sender, EventArgs e)
{
if
(INPUT.Text !=
""
)
INPUT.Text = INPUT.Text.Substring(0, INPUT.Text.Length - 1);
}
private
void
CE_Click(
object
sender, EventArgs e)
{
INPUT.Text =
""
;
ANSWER.Text =
""
;
}
private
void
CE_Click_1(
object
sender, EventArgs e)
{
INPUT.Text =
""
;
ANSWER.Text =
""
;
}
private
void
DECIMAL_Click(
object
sender, EventArgs e)
{
INPUT.Text +=
"."
;
}
private
void
INPUT_TextChanged(
object
sender, EventArgs e)
{
}
}
}
Reply
Answers (
1
)
Help and some tips in creating winforms application
How to change the content of other computers by using one PC