سلام.
تو رویداد KeyPress بنویسید.
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if (!(char.IsDigit(e.KeyChar) || e.KeyChar == '-')) { e.Handled = true; } }
اگر به backspace هم نیاز داشتید:
if (!(char.IsDigit(e.KeyChar) || e.KeyChar == '-' || e.KeyChar == (char)Keys.Back)) { e.Handled = true; }
2,337 سوال
2,871 پاسخ
3,725 دیدگاه
3,921 کاربر