In: Computer Science
Using C# Windows App Form
Create a simple calculator using +,-,*,/
Please show
code
GUI
Code for calculator
menus
radio button
input text boxes
Code
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 Calculator_Simple
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double num1, num2, ans;
private void rdbAdd_CheckedChanged(object sender, EventArgs
e)
{
getNumbers();
txtAns.Text = (num1 + num2).ToString();
}
private void getNumbers()
{
num1 = Convert.ToDouble(txtNum1.Text);
num2 = Convert.ToDouble(txtNum2.Text);
}
private void rdbSub_CheckedChanged(object sender, EventArgs
e)
{
getNumbers();
txtAns.Text = (num1 - num2).ToString();
}
private void rdbMul_CheckedChanged(object sender, EventArgs
e)
{
getNumbers();
txtAns.Text = (num1 * num2).ToString();
}
private void rdbDiv_CheckedChanged(object sender, EventArgs
e)
{
getNumbers();
if (num2 != 0)
{
txtAns.Text = (num1 / num2).ToString();
}
else
{
MessageBox.Show("Denominator can't b 0.");
}
}
}
}
outputs
design
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.