如何在Windows窗体应用程序只允许字母在一个文本框? [英] How to permit only letters in a textbox in a Windows Forms application?

查看:131
本文介绍了如何在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;
    }
}

这篇关于如何在Windows窗体应用程序只允许字母在一个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆