Дополнен 11 лет назад
Никогда не думала что эти комментарии настолько трудно прочесть ...Хотелось просто спросить как смотря на этот код сделать чтоб при нажатии на кнопку - у меня работало вычитание а нажав кнопку = выводился результат ...Про траву отдельный разговор по себе не судите
{
int x, y, dx, dy;//dx, dy smewenie
int cx = 20, cy = 20;
int col, row;//col, row wirina vysota
dx = cx + cx / 4;//rastojanie mezdu knopkami
dy = cy + cy / 4;
string[,] textBtn ={
{"7","8","9", "/","<-"},
{"4","5","6", "*","C"},
{"1","2","3", "-","="},
{"0"," +/-",separ.ToString(), "+",""}};
MyButton btn;
Color color = Color.Green;
//Color color = this.ForeColor;
for (row = 0, y = y_begin;
row <= textBtn.GetUpperBound(0);
row++, y += dy)
{
for (col = 0, x = x_begin;
col <= textBtn.GetUpperBound(1);
col++, x += dx)
{
if (row == 3 && col == 4)
break;//continuo esli v centre
cy = 20;
if (col == 4 && row == 2)// 4toby sdelatj knopku "=" v 2 raza boljwe
{
cy += dy;
}
color = Color.Green;
if (col == 3 || col == 4)
{
color = Color.Blue;
}
btn = new MyButton(this, textBtn[row, col],
color, x, y, cx, cy);
//obrabot4ik sobytija
btn.Click += new EventHandler(btn_Click);
}
}
}
void btn_Click(object sender, EventArgs e)
{
MyButton btn = (MyButton)sender;
char chOperation = btn.Text[0];
if (chOperation >= '0' && chOperation <= '9')//esli eto cifra to
{
text.Text += btn.Text;// sozdajotsja cepo4ka zna4enij
}
if (chOperation == '+')
{
sum += Double.Parse(text.Text);
text.Text = "";
}
if (chOperation == '=')
{
sum += Double.Parse(text.Text);
text.Text = sum.ToString();
}
ПРОБЛЕМА СОСТОИТ В ТОМ ЧТО ДЕЛАЮ КАЛЬКУЛЯТОР ВОТ СДЕЛАЛА ОПЕРАЦИЮ + НО ЕСЛИ ДЕЛАТЬ ПО ТАКОМУ ПРИНЦИПУ УМНОЖЕНИЕ ДЕЛЕНИЕ ИЛИ ВЫЧИТАНИЕ СЧЕТ РЕЗУЛЬТАТА ПРОИСХОДИТ ОЧЕНЬ СТРАННО