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
Mike Smile
NA
8
539
my c# calculator only accepts one digit after selecting an o
Apr 1 2020 3:05 PM
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 WindowsFormsApplication1
{
public partial class CALCULATOR : Form
{
Double ResultsCalur = 0;
string operationPerformed = "";
bool isOperationPerformed = false;
public CALCULATOR()
{
InitializeComponent();
}
private void button14_Click(object sender, EventArgs e)
{
}
private void CALCULATOR_Load(object sender, EventArgs e)
{
}
private void txtdivide_Click(object sender, EventArgs e)
{
}
private void btnce_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
}
private void btnc_Click(object sender, EventArgs e)
{
textBox1.Text = "0";
ResultsCalur = 0;
}
private void txtequals_Click(object sender, EventArgs e)
{
switch (operationPerformed)
{
case "+":
textBox1.Text = (ResultsCalur + Double.Parse(textBox1.Text)).ToString();
break;
case "-":
textBox1.Text = (ResultsCalur - Double.Parse(textBox1.Text)).ToString();
break;
case "/":
textBox1.Text = (ResultsCalur / Double.Parse(textBox1.Text)).ToString();
break;
case "*":
textBox1.Text = (ResultsCalur * Double.Parse(textBox1.Text)).ToString();
break;
}
ResultsCalur = Double.Parse(textBox1.Text);
lblcurrentopp.Text = " ";
}
private void btn0_Click(object sender, EventArgs e)
{
if ((textBox1.Text == "0") || (isOperationPerformed))
textBox1.Clear();
Button button = (Button)sender;
if(button.Text ==".")
{
if (!textBox1.Text.Contains("."))
textBox1.Text = textBox1.Text + button.Text;
}else
textBox1.Text = textBox1.Text + button.Text;
}
private void txtplus_Click_1(object sender, EventArgs e)
{
Button button = (Button)sender;
if(ResultsCalur != 0){
txtequals.PerformClick();
operationPerformed = button.Text;
lblcurrentopp.Text = ResultsCalur + " " + operationPerformed;
isOperationPerformed = true;
}
else {
operationPerformed = button.Text;
ResultsCalur = Double.Parse(textBox1.Text);
lblcurrentopp.Text = ResultsCalur + " " + operationPerformed;
isOperationPerformed = true;
}
}
}
}
Reply
Answers (
3
)
Write a program, that reads user input until an empty line
How to handle millions of graphic objects in WPF C#