c# 只能输入字母或者数字 或者退格符 

方法一:KeyPress

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar != '\b') &&(!Char.IsLetter(e.KeyChar)) && (!char.IsDigit(e.KeyChar)))
            {
                e.Handled = true;
            }

        }

 

 

 

 

方法二: 正则表达式

添加引用

using System;
using System.Text.RegularExpressions;

 

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-30
  • 2022-12-23
  • 2022-02-04
  • 2021-08-05
  • 2021-06-07
相关资源
相似解决方案