Guest User

Untitled

a guest
Dec 16th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace CalcTwo
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18.  
  19. }
  20.  
  21.  
  22. string input = string.Empty;
  23. double numb1, numb2, result;
  24.  
  25.  
  26. private void button1_Click(object sender, EventArgs e)
  27. {
  28. double.TryParse(textBox1.Text, out numb1);
  29. double.TryParse(textBox2.Text, out numb2);
  30. result = numb1 + numb2;
  31. textBox3.Text = result.ToString();
  32. }
  33.  
  34. private void button4_Click(object sender, EventArgs e)
  35. {
  36. double.TryParse(textBox1.Text, out numb1);
  37. double.TryParse(textBox2.Text, out numb2);
  38. result = numb1 - numb2;
  39. textBox3.Text = result.ToString();
  40. }
  41. }
  42. }
  43.  
  44. private void CaptureValues()
  45. {
  46. double.TryParse(textBox1.Text, out numb1);
  47. double.TryParse(textBox2.Text, out numb2);
  48. }
  49.  
  50. private void button1_Click(object sender, EventArgs e)
  51. {
  52. CaptureValues();
  53. result = numb1 + numb2;
  54. textBox3.Text = result.ToString();
  55. }
  56.  
  57. private void CaptureValues()
  58. {
  59. if (!double.TryParse(textBox1.Text, out numb1))
  60. // textBox1 couldn't be parsed, show an error message
  61. if (!double.TryParse(textBox2.Text, out numb2))
  62. // textBox2 couldn't be parsed, show an error message
  63. }
  64.  
  65. private double Value1
  66. {
  67. get
  68. {
  69. double result;
  70. if (!double.TryParse(textBox1.Text, out result))
  71. throw new Exception("Couldn't parse the first text box!");
  72. return result;
  73. }
  74. }
  75.  
  76. private double Value2
  77. {
  78. get
  79. {
  80. double result;
  81. if (!double.TryParse(textBox2.Text, out result))
  82. throw new Exception("Couldn't parse the second text box!");
  83. return result;
  84. }
  85. }
  86.  
  87. textBox3.Text = (Value1 + Value2).ToString();
  88.  
  89. try
  90. {
  91. textBox3.Text = (Value1 + Value2).ToString();
  92. }
  93. catch (Exception ex)
  94. {
  95. // examine what happened with ex and show an error
  96. }
Add Comment
Please, Sign In to add comment