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 Training1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BTN1_Click(object sender, EventArgs e)
{
int n1 = Convert.ToInt32(txtnum1.Text);
int n2 = Convert.ToInt32(txtnum2.Text);
int sum = 0 ;
sum = n1 + n2;
// MessageBox.Show(sum.ToString());
txttotal.Text = (sum.ToString());
}
private void BTN2_Click(object sender, EventArgs e)
{
int n1 = Convert.ToInt32(txtnum1.Text);
int n2 = Convert.ToInt32(txtnum2.Text);
int sum = 0;
sum = n1 - n2;
// MessageBox.Show(sum.ToString());
txttotal.Text = (sum.ToString());
}
}
}
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 Training1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//ประกาศตัวแปรให้ใช้ได้ทั้ง class รึป่าวครับ แบบนี้
int n1 =0;
int n2 = ;
int sum = 0 ;
private void BTN1_Click(object sender, EventArgs e)
{
n1 = Convert.ToInt32(txtnum1.Text);
n2 = Convert.ToInt32(txtnum2.Text);
sum = n1 + n2;
// MessageBox.Show(sum.ToString());
txttotal.Text = (sum.ToString());
}
private void BTN2_Click(object sender, EventArgs e)
{
n1 = Convert.ToInt32(txtnum1.Text);
n2 = Convert.ToInt32(txtnum2.Text);
sum = n1 - n2;
// MessageBox.Show(sum.ToString());
txttotal.Text = (sum.ToString());
}
}
}