Try this.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private readonly int firstbox;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void button1_Click(object sender, EventArgs e)
{
int firstbox = Int32.Parse( textBox1.Text ); //here you input first value
int firstvalue = Int32.Parse( textBox1.Text ); // this is to store the first value you write in textbox
textBox1.Text = ""; //this is so that the textbox clears after the click
}
public void button2_Click(object sender, EventArgs e)
{
int secondbox = Int32.Parse( textBox1.Text ); //second input!
int secondvalue = Int32.Parse( textBox1.Text ); //this is to store the second value that you input after buttonclick
int result = firstbox + secondbox; //the sum
int limitbox = Int32.Parse( textBox2.Text ); //limit!
if (result <= limitbox)
{ //if you only write < and the MAX is 20, it will give you Invalid because 20 is not less than 20
textBox1.Text = result.ToString();
}
else
{
MessageBox.Show("Invalid input");
}
}
}
}
I made firstbox an instance variable otherwise it would have been out of context.
Remember to edit the namespace. You may also need to remove readonly.