Ниже приведена моя программа для caluculator но мы вводим значения keybord не принимая их
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class calc : System.Web.UI.Page { static float a, c, d; static char b; protected void Page_Load(object sender, EventArgs e) { } protected void btn_1_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_1.Text; } else { tb.Text = tb.Text + btn_1.Text; } } protected void btn_2_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_2.Text; } else { tb.Text = tb.Text + btn_2.Text; } } protected void btn_3_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_3.Text; } else { tb.Text = tb.Text + btn_3.Text; } } protected void btn_4_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_4.Text; } else { tb.Text = tb.Text + btn_4.Text; } } protected void btn_5_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_5.Text; } else { tb.Text = tb.Text + btn_5.Text; } } protected void btn_6_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_6.Text; } else { tb.Text = tb.Text + btn_6.Text; } } protected void btn_7_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_7.Text; } else { tb.Text = tb.Text + btn_7.Text; } } protected void btn_8_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_8.Text; } else { tb.Text = tb.Text + btn_8.Text; } } protected void btn_9_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_9.Text; } else { tb.Text = tb.Text + btn_9.Text; } } protected void btn_0_Click(object sender, EventArgs e) { if ((tb.Text == "+") || (tb.Text == "-") || (tb.Text == "*") || (tb.Text == "/")) { tb.Text = ""; tb.Text = tb.Text + btn_0.Text; } else { tb.Text = tb.Text + btn_0.Text; } } protected void btn_add_Click(object sender, EventArgs e) { a = Convert.ToInt32(tb.Text); tb.Text = ""; b = '+'; tb.Text += b; } protected void btn_sub_Click(object sender, EventArgs e) { a = Convert.ToInt32(tb.Text); tb.Text = ""; b = '-'; tb.Text += b; } protected void btn_product_Click(object sender, EventArgs e) { a = Convert.ToInt32(tb.Text); tb.Text = ""; b = '*'; tb.Text += b; } protected void btn_div_Click(object sender, EventArgs e) { a = Convert.ToInt32(tb.Text); tb.Text = ""; b = '/'; tb.Text += b; } protected void btn_eql_Click(object sender, EventArgs e) { c = Convert.ToInt32(tb.Text); tb.Text = ""; if (b == '/') { d = a / c; tb.Text += d; a = d; } else if (b == '+') { d = a + c; tb.Text += d; a = d; } else if (b == '-') { d = a - c; tb.Text += d; a = d; } else { d = a * c; tb.Text += d; a = d; } } protected void btn_clr_Click(object sender, EventArgs e) { tb.Text = ""; } }
Что я уже пробовал:
я пытался калюкать его беря только с кнопки а не с клавиатуры
HobbyProggy
Насколько я вижу, вам не хватает события "KeyDown", которое срабатывает при нажатии любой клавиши на клавиатуре.
Richard MacCutchan
Вы можете значительно улучшить ситуацию, избавившись от всего этого дублирующего кода. Вам нужен только один обработчик для события keydown и общая подпрограмма для чисел.