C# 只允许输入C、O、M、数字、删除键
可以通过以下代码实现:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
e.KeyChar != 'C' && e.KeyChar != 'O' && e.KeyChar != 'M')
{
e.Handled = true;
}
}
在文本框的 KeyPress 事件中,判断输入的字符是否为数字、C、O、M 或者删除键,如果不是则将事件标记为已处理,不允许输入。
原文地址: https://www.cveoy.top/t/topic/b8iC 著作权归作者所有。请勿转载和采集!