Delphi
Visual C# . 14.
"".
.
C#
. ,
, :

"+":
private void
button1_Click(object sender,
EventArgs e)
{
label1.Text = (sender as
Button).Text;
} |
"-", "*","/".
:

, ,
Click
:

"=":
private void
button5_Click(object sender,
EventArgs e)
{
double x = 0;
double x1;
double x2;
if (!double.TryParse(textBox1.Text,
out x1) || !double.TryParse(textBox2.Text,
out x2))
{
label2.Text = "ERROR";
return;
}
else
{
switch (label1.Text[0])
{
case
'+':
x = x1 + x2; break;
case
'-':
x = x1 - x2; break;
case
'*':
x = x1 * x2; break;
case
'/':
x = x1 / x2; break;
}
label2.Text = "= " + x;
}
} |
.
"+","-","*" "/" ,
, , .
( , ),
sender.
.
, ,
.
- "&":

:

,
, - .
, ,
"=":
private void
button5_Click(object sender,
EventArgs e)
{
double x = 0;
double x1;
double x2;
if (!double.TryParse(textBox1.Text,
out x1) || !double.TryParse(textBox2.Text,
out x2))
{
label2.Text = "ERROR";
return;
}
else
{
switch (label1.Text[1])
{
case
'+':
x = x1 + x2; break;
case
'-':
x = x1 - x2; break;
case
'*':
x = x1 * x2; break;
case
'/':
x = x1 / x2; break;
}
label2.Text = "= " + x;
}
} |
. ,
, :
private void
button1_Click(object sender,
EventArgs e)
{
label1.Text = (sender as
Button).Text;
label2.Text = "=";
} |
. :
private void
textBox1_TextChanged(object sender,
EventArgs e)
{
label2.Text =
"=";
} |
,
KeyPress:
private void
Form1_KeyPress(object sender,
KeyPressEventArgs e)
{
char c = e.KeyChar;
char sep =
Application.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];
switch (c)
{
case
'+':
button1_Click(button1, null);
break;
case
'x':
case
'*':
button1_Click(button3, null);
break;
case
'-':
button1_Click(button2, null);
break;
case
'/':
button1_Click(button4, null);
break;
}
e.Handled = !(char.IsDigit(c) ||
c == sep || c == '-' || c ==
'\b');
} |
.
, :

:
"=" (
). , Form1_KeyPress:
private void
Form1_KeyPress(object sender,
KeyPressEventArgs e)
{
char c = e.KeyChar;
char sep =
Application.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];
switch (c)
{
case
'+':
button1_Click(button1, null);
break;
case
'x':
case
'*':
button1_Click(button3, null);
break;
case
'-':
button1_Click(button2, null);
break;
case
'/':
button1_Click(button4, null);
break;
case
'=':
button5_Click(button5, null);
break;
}
e.Handled = !(char.IsDigit(c) ||
c == sep || c == '-' || c ==
'\b');
} |
, *,
"Microsoft Visual Studio 2010 Professional",
Microsoft..
()
|