In this example, I will show you how to add two numbers in Windows Form Application.
Screenshot of the program that adds the number entered in two TextBox and prints the result on the label element.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Add_button_Click(object sender, EventArgs e) { try { double a = Convert.ToDouble(textBox1.Text); double b = Convert.ToDouble(textBox2.Text); textBox3.Text = (a + b).ToString(); } catch(Exception) { MessageBox.Show("invalid input"); } } } |