Difficulty with try and catch statements?
How in the world do I set a try and catch to stop the user from inputting
more than one decimal. Is it a try and catch? Or what exactly do i want to
do here? Very new to windows form applications....
Also somewthing to note... when I click the calculations the numbers
dissapear.. it doesn't continuously stay there. I thought that was odd.
Would anyone know why? For example if I hit 6 + 6 it shows "6" and then
another "6" and then 12, not a display of 6 + 6 = 12. I dont understand
that either
public partial class Form1 : Form
{
string c;
double num1;
double num2;
public Form1()
{
InitializeComponent();
}
private void button11_Click(object sender, EventArgs e)
{
textBox1.AppendText("0");
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.AppendText("1");
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.AppendText("2");
}
private void button5_Click(object sender, EventArgs e)
{
textBox1.AppendText("3");
}
private void button6_Click(object sender, EventArgs e)
{
textBox1.AppendText("4");
}
private void button7_Click(object sender, EventArgs e)
{
textBox1.AppendText("5");
}
private void button8_Click(object sender, EventArgs e)
{
textBox1.AppendText("6");
}
private void button15_Click(object sender, EventArgs e)
{
textBox1.AppendText("7");
}
private void button16_Click(object sender, EventArgs e)
{
textBox1.AppendText("8");
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.AppendText("9");
}
private void button9_Click(object sender, EventArgs e)
{
textBox1.Clear();
}
private void button10_Click(object sender, EventArgs e)
{
textBox1.AppendText(".");
}
private void button3_Click(object sender, EventArgs e)
{
c = "+";
num1 = double.Parse(textBox1.Text);
textBox1.Text = string.Empty;
}
private void button12_Click(object sender, EventArgs e)
{
c = "-";
num1 = double.Parse(textBox1.Text);
textBox1.Text = string.Empty;
}
private void button13_Click(object sender, EventArgs e)
{
c = "*";
num1 = double.Parse(textBox1.Text);
textBox1.Text = string.Empty;
}
private void button14_Click(object sender, EventArgs e)
{
c = "/";
num1 = double.Parse(textBox1.Text);
textBox1.Text = string.Empty;
}
private void button4_Click(object sender, EventArgs e)
{
num2 = double.Parse(textBox1.Text);
double result;
if (c == "+")
{
result = num1 + num2;
textBox1.Text = result.ToString();
}
else if (c == "-")
{
result = num1 - num2;
textBox1.Text = result.ToString();
}
else if (c == "*")
{
result = num1 * num2;
textBox1.Text = result.ToString();
}
else if (c == "/")
{
result = num1 / num2;
textBox1.Text = result.ToString();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
No comments:
Post a Comment