C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Base Blockchain
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
Key Presses in a calculator. Please Read
Adam Hearst
6y
678
1
Reply
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)
{
}
}
}
Rich Text Editor, TextBoxComment
Editor toolbars
Editing
Undo
Keyboard shortcut Ctrl+Z
Redo
Keyboard shortcut Ctrl+Y
Remove Format
Clipboard/Undo
Cut
Keyboard shortcut Ctrl+X
Copy
Keyboard shortcut Ctrl+C
Tools
Maximize
Styles
Format
Format
Paragraph
Insert/Remove Numbered List
Insert/Remove Bulleted List
Decrease Indent
Increase Indent
Block Quote
Basic Styles
Bold
Keyboard shortcut Ctrl+B
Italic
Keyboard shortcut Ctrl+I
Links
Link
Keyboard shortcut Ctrl+K
Unlink
Insert
Image
Insert Code Snippet
Table
Document
Source
Press ALT 0 for help
◢
Elements path
Post
Reset
Cancel
Answers (
1
)
0
Bryian Tan
NA
9.7k
1.6m
6y
this might help : https://stackoverflow.com/questions/19090169/want-to-add-keyboard-input-to-my-calculator-also-hide-the-mouse-cursors
Accepted
Next Recommended Forum
Help and some tips in creating winforms application
How to change the content of other computers by using one PC