01/10/2018, 11:41
Lỗi khi làm Windows app
Em click vào các button thì toàn bị như trong hình
namespace CTNC2
{
public partial class Form1 : Form
{
public System.Windows.Forms.TextBox tbtoantu1;
public System.Windows.Forms.TextBox tbtoantu2;
public System.Windows.Forms.TextBox tbketqua;
public Form1()
{
InitializeComponent();
}
protected void Form1_Load(object sender, EventArgs e)
{
}
protected void cong_Click(object sender, EventArgs e)
{
int toantu1 = Int32.Parse(tbtoantu1.Text);
int toantu2 = Int32.Parse(tbtoantu1.Text);
int ketqua = toantu1 + toantu2;
tbketqua.Text = ketqua.ToString();
}
protected void tru_Click(object sender, EventArgs e)
{
int toantu1 = Int32.Parse(tbtoantu1.Text);
int toantu2 = Int32.Parse(tbtoantu2.Text);
int ketqua = toantu1 - toantu2;
tbketqua.Text = ketqua.ToString();
}
protected void nhan_Click(object sender, EventArgs e)
{
int toantu1 = Int32.Parse(tbtoantu1.Text);
int toantu2 = Int32.Parse(tbtoantu1.Text);
int ketqua = toantu1 * toantu2;
tbketqua.Text = ketqua.ToString();
}
protected void chia_Click(object sender, EventArgs e)
{
int toantu1 = Int32.Parse(tbtoantu1.Text);
int toantu2 = Int32.Parse(tbtoantu1.Text);
if (toantu2 == 0)
{
tbketqua.Text = "ERROR";
}
else
{
double ketqua = (double)toantu1 / toantu2;
tbketqua.Text = ketqua.ToString();
}
}
private void thoat_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
Bài liên quan
Hi Duc Ngo.
tbtoantu1 was null.
Ngoài lề tí
Ngày xưa gặp
NullReferenceException
là phải debug mới biết thằng nào null. Giờ VS2017 nó báo lỗi do thằng nào luôn, quá tiệnBạn làm app bằng Qt á, đẹp quá
Cái này C# Winform (đoán thế )
Tớ định làm cái app
Tính tiền điện bằng Qt
, không biết @SakaDream có lời khuyên nào không nhỉ ?Mình không rành Qt bạn à
@Duc_Ngo1 có lời khuyên gì về làm giao diện không? Thấy hứng thù với giao diện quá .[quote=“pro, post:6, topic:54821, full:true”]
Tớ định làm cái app Tính tiền điện bằng Qt , không biết @SakaDream có lời khuyên nào không nhỉ ?
[/quote]
Khai báo cái này để làm gì đây ??
chỉ là khai báo thôi!! tks mọi người đã bình luận
trong khi 2 cái textbox trong hình thì không ai biết tên của nó, em lại khai báo 2 cái textbox mới trong code rồi gọi hàm với 2 cái textbox null đó
Cái này là sao v bạn?
ojk anh, để e sửa thử xem