如何在Windows窗体应用程序只允许字母在一个文本框?

问题描述:

我怎么能允许字母从A到Z的在Windows文本框窗体应用程序。什么是源$ C ​​$ C在C#?

How can I permit letters from A to Z in a textbox in a Windows Forms application. What is the source code in C#?

在构造函数或通过设计师:

in your constructor or via designer:

textBox.KeyPress += new KeyPressEventHandler(textBox_KeyPress);

然后事件处理程序:

Then the event handler:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar < 65 || e.KeyChar > 122)
    {
        e.Handled = true;
    }
}