// كود لحساب مساحة و محيط المستطيل
private void calculBtn_Click(object sender, EventArgs
e)
{
int x, y,
surface, env;
String s="";
if
(XTextBox.Text != "" &&
YTextBox.Text != "")
{
x = int.Parse(XTextBox.Text);
y = int.Parse(YTextBox.Text);
surface = x
* y;
env = (x +
y) * 2;
s = "المساحة الجملية للمستطيل = "+surface+"
"+ListUnites.Text+"²";
ResultList.Items.Add(s);
s = "محيط المستطيل = " + env + "
" + ListUnites.Text;
ResultList.Items.Add(s);
}
else {
MessageBox.Show("قم بإدخال طول و عرض المستطيل ثم اضغط على زر حساب");
}
}
// كود لمراقبة ما يكتبه المستخدم
private void XTextBox_KeyPress(object sender, KeyPressEventArgs
e)
{
if(!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void YTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled
= true;
}
}
ليست هناك تعليقات:
إرسال تعليق