实现如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PISS.View.CustomControl
{
public class LetterAndNum : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);

SetStandard(e);
}

private void SetStandard(System.Windows.Forms.KeyPressEventArgs e)
{
//只允许输入字母
Regex regex = new Regex(@"^([A-Za-z0-9]|[\b])+$");
MatchCollection mc = regex.Matches(e.KeyChar.ToString());
foreach (Match ma in mc)
{
e.Handled = false;
return;
}

e.Handled = true;
}
}
}

TextBox(只允许输入字母或者数字)——重写控件的更多相关文章

  1. TextBox(只允许输入字母或者数字)

    实现如下: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System ...

  2. WPF TextBox 的 EventTrigger & 重写控件

    遇到一个需求,在textbox获得焦点的时候,调用一个外部的软键盘. 这可以用两个不同的方法来达到目的. 1.EventTrigger 首先定义一个Style <Style x:Key=&quo ...

  3. html只允许输入的数据校验,只允许输入字母汉字数字等

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. WPF自定义数字输入框控件

    要求:只能输入数字和小数点,可以设置最大值,最小值,小数点前长度,小数点后长度(支持绑定设置): 代码如下: using System; using System.Collections.Generi ...

  5. Delphi 重写控件的一个例子。

    unit DBGridEx;   interface   uses   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, ...

  6. 只显示年月的js时间控件 纯手写

    <style> #date { text-align: center; } .td { cursor: pointer; } </style> <script> f ...

  7. 数字调节控件JSpinner的使用

    ---------------siwuxie095                         工程名:TestUI 包名:com.siwuxie095.ui 类名:TestList.java   ...

  8. TextBox控件

    1.通过设置Multiline属性(bool)来控制文本框是否为多行显示 txt_Change.Location = , );//设置文本框位置 txt_Change.Multiline = true ...

  9. WPF 控件功能重写(ComboBox回车搜索)

    前言:在我们日常使用软件的时候,Combobox会让用户很方便的选择出需要的东西,但是ComboBox中的下拉行数过多时就不那么好用了. 如果在项目中有很多这样的ComboBox控件的话,我们可以考虑 ...

随机推荐

  1. python随机数,随机选择……random

    import random from random import random, uniform, randint, randrange, choice, sample, shuffle list = ...

  2. 添加MyEclipse WebSphere Portal Server支持(一)

    [周年庆]MyEclipse个人授权 折扣低至冰点!立即开抢>> [MyEclipse最新版下载] 一.支持WebSphere Portal Server 本文档介绍了如何支持和开发 We ...

  3. bjui的validate表单验证的使用

    date-rule ="date" 表示格式为yyyy-MM-dd date-rule = "datetime" 表示格式为yyyy-MM-dd HH:mm:s ...

  4. 免费申请一年版Eset NOD32 Antivirus激活码(无限制)- 已失效

    You will receive a 1-year license of the antivirus software Eset NOD32 (version 6), including all up ...

  5. php session和cookie知识

  6. 将PS/2接口鼠标改造成USB接口鼠标

    改造接线图 不是所有PS/2鼠标都可以改为USB鼠标的,可以改的PS/2鼠标的特征: A.早期PS/2鼠标电路板一般带有两块集成电路,(一块光电感应,一块按键或USB协议转换,和一只24M的晶体振荡器 ...

  7. 部署python3.6下的django

    首先是安装好nginx,配置web目录,配置文件在confi.d中, server { # the port your site will be served on listen ; # the do ...

  8. Linux Framebuffer save as picture

    /********************************************************************************* * Linux Framebuff ...

  9. Tomcat下JSP、Servlet和JavaBean环境的配置

    经常看到jsp的初学者问tomcat下如何配置jsp.servlet和bean的问题,于是总结了一下如何tomcat下配置jsp.servlet和ben,希望对那些初学者有所帮助. 第一步:下载j2s ...

  10. C#单例的多种写法

    单例的细分写法 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 最吊大的 一种--C#这样的高级语言特有 ...