文本框只输入数字

 private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(e.KeyChar >= 48 && e.KeyChar <= 57 || e.KeyChar == 8))//8是BackSpace的键码
            {
                e.Handled = true;
            }
        }
 
 
 
 
 
 

你可能感兴趣的:(object,textbox)