Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 CalcTwo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string input = string.Empty;
- double numb1, numb2, result;
- private void button1_Click(object sender, EventArgs e)
- {
- double.TryParse(textBox1.Text, out numb1);
- double.TryParse(textBox2.Text, out numb2);
- result = numb1 + numb2;
- textBox3.Text = result.ToString();
- }
- private void button4_Click(object sender, EventArgs e)
- {
- double.TryParse(textBox1.Text, out numb1);
- double.TryParse(textBox2.Text, out numb2);
- result = numb1 - numb2;
- textBox3.Text = result.ToString();
- }
- }
- }
- private void CaptureValues()
- {
- double.TryParse(textBox1.Text, out numb1);
- double.TryParse(textBox2.Text, out numb2);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- CaptureValues();
- result = numb1 + numb2;
- textBox3.Text = result.ToString();
- }
- private void CaptureValues()
- {
- if (!double.TryParse(textBox1.Text, out numb1))
- // textBox1 couldn't be parsed, show an error message
- if (!double.TryParse(textBox2.Text, out numb2))
- // textBox2 couldn't be parsed, show an error message
- }
- private double Value1
- {
- get
- {
- double result;
- if (!double.TryParse(textBox1.Text, out result))
- throw new Exception("Couldn't parse the first text box!");
- return result;
- }
- }
- private double Value2
- {
- get
- {
- double result;
- if (!double.TryParse(textBox2.Text, out result))
- throw new Exception("Couldn't parse the second text box!");
- return result;
- }
- }
- textBox3.Text = (Value1 + Value2).ToString();
- try
- {
- textBox3.Text = (Value1 + Value2).ToString();
- }
- catch (Exception ex)
- {
- // examine what happened with ex and show an error
- }
Add Comment
Please, Sign In to add comment