允许在文本框中只有字母数字框中、字母、文本、数字

2023-09-04 22:31:29 作者:後會無期’

我有一个文本框,应该禁止进入任何特殊字符。

用户可以输入:

A-Z A-Z 0-9 空格

我怎样才能让的KeyDown 事件来做到这一点?

解决方案

 私人无效_txtPath_KeyDown(对象发件人,KeyEventArgs E)
  {
     如果((e.Key< Key.A)||(e.Key> Key.Z))
        e.Handled =真实;
  }
 

VB编程 我想在第一个文本框中随意输入字母和数字,第二个文本框用来显示其中的数字,我该怎么改

I have a textbox that should disallow entering any special characters.

The user can enter :

A-Z a-z 0-9 Space

How can I make the KeyDown event to do this?

解决方案

private void _txtPath_KeyDown(object sender, KeyEventArgs e)
  {
     if ((e.Key < Key.A) || (e.Key > Key.Z))
        e.Handled = true;
  }