Tuần 1 - Bài 3
Source fBai3.cs
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 Bai3
{
public partial class fBai3 : Form
{
public fBai3()
{
InitializeComponent();
if (Test() == false)
{
btnCout.Enabled = false;
btnClear.Enabled = false;
}
}
private bool Test()
{
if ((txbInputA.Text.Length == 0 || txbInputB.Text.Length == 0) || ((!Char.IsDigit(txbInputA.Text[txbInputA.Text.Length - 1])) || (!Char.IsDigit(txbInputB.Text[txbInputB.Text.Length - 1]))))
return false;
return true;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult r;
r = MessageBox.Show("Thí chủ muốn thoát chứ?",
"THÔNG BÁO NÈ!", MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (r == DialogResult.No)
e.Cancel = true;
}
private void txbInputA_TextChanged(object sender, EventArgs e)
{
if (Test() == false)
{
btnCout.Enabled = false;
btnClear.Enabled = false;
}
else if (Test() == true)
{
btnCout.Enabled = true;
btnClear.Enabled = true;
}
//////////////////////////
///
Control ctr = (Control)sender;
if(ctr.Text.Length >0 && !Char.IsDigit(ctr.Text[ctr.Text.Length - 1]))
{
this.erroNotify.SetError(ctr, "This is not value number!");
txbResult.Text = "Thí chủ nhấn nhầm rồi kìa!";
}
else
{
this.erroNotify.Clear();
txbResult.Text = "";
}
}
private void txbInputB_TextChanged(object sender, EventArgs e)
{
if (Test() == false)
{
btnCout.Enabled = false;
btnClear.Enabled = false;
}
else if (Test() == true)
{
btnCout.Enabled = true;
btnClear.Enabled = true;
}
////////////////
Control ctr = (Control)sender;
if (ctr.Text.Length > 0 && !Char.IsDigit(ctr.Text[ctr.Text.Length - 1]))
{
this.erroNotify.SetError(ctr, "This is not value number!");
txbResult.Text = "Thí chủ nhấn nhầm rồi kìa!";
}
else
{
this.erroNotify.Clear();
txbResult.Text = "";
}
}
private void btnClear_Click(object sender, EventArgs e)
{
ClearData();
}
private void ClearData()
{
txbInputA.Clear();
txbInputB.Clear();
txbResult.Clear();
txbInputA.Focus();
}
private void btnCout_Click(object sender, EventArgs e)
{
int a, b;
double c;
if (txbInputA.Text.Length == 0 && txbInputB.Text.Length == 0)
{
txbResult.Text = "Thí chủ không có gì để tính toán cả!";
}
else if (txbInputA.Text.Length == 0 || txbInputB.Text.Length == 0)
{
txbResult.Text = "Thí chủ nhập thiếu rồi kìa!";
}
else
{
a = Convert.ToInt32(txbInputA.Text);
b = Convert.ToInt32(txbInputB.Text);
if (a == 0 && b == 0)
txbResult.Text = "Phương trình có cả đống nghiệm!";
else if(a == 0 && b!= 0)
txbResult.Text = "Phương trình vô nghiệm rồi bạn!";
else if(a != 0)
{
c = (double)-b / (double)a;
c = Math.Round(c, 3);
txbResult.Text = "X = " + c.ToString();
}
}
}
}
}


























No Comment to " Tuần 1 - Bài 3 "