C# TextBox控件实现只能输入数字的方法
作者:junjie 时间:2022-03-07 01:57:27
只需要在控件TextBox的keypress事件中写入如下代码即可满足要求:
代码如下:
if (e.KeyChar == '.' && this.txbEnd.Text.IndexOf(".") != -1)
{
e.Handled = true;
}
if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
{
e.Handled = true;
}
其中.txbEnd为当前你窗体中textbox控件的name
标签:C#,TextBox,控件,数字
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java8中forEach语句循环一个List和Map
2021-06-02 07:03:54
Spring Boot 整合持久层之Spring Data JPA
2022-07-29 04:00:38
![](https://img.aspxhome.com/file/2023/9/62689_0s.png)
Java反射机制的简单讲解
2023-12-12 20:49:13
![](https://img.aspxhome.com/file/2023/6/64796_0s.png)
解析Tars-Java客户端源码
2023-04-08 01:18:39
![](https://img.aspxhome.com/file/2023/7/89587_0s.jpg)
浅谈Hibernate对象状态之间的神奇转换
2021-12-18 02:13:18
![](https://img.aspxhome.com/file/2023/7/75477_0s.png)
Java 手写LRU缓存淘汰算法
2023-03-03 00:11:19
![](https://img.aspxhome.com/file/2023/0/64100_0s.jpg)
java新人基础入门之递归调用
2023-11-10 01:15:16
![](https://img.aspxhome.com/file/2023/1/90981_0s.png)
浅谈Mybatis获取参数值的方式
2022-09-22 07:56:21
![](https://img.aspxhome.com/file/2023/0/65770_0s.jpg)
Spring Cloud Gateway替代zuul作为API网关的方法
2023-05-03 07:19:58
![](https://img.aspxhome.com/file/2023/8/69738_0s.jpg)
Cocos2d-x 3.0多线程异步加载资源实例
2022-02-08 03:26:51
详解Java线程堆栈
2021-06-29 03:37:38
java多线程中执行多个程序的实例分析
2023-03-11 18:21:58
C#控制图像旋转和翻转的方法
2023-11-26 08:25:08
Android 动态加载二维码视图生成快照的示例
2023-08-04 19:57:54
![](https://img.aspxhome.com/file/2023/9/84719_0s.png)
Java——对象初始化顺序使用详解
2023-11-01 01:08:46
java多线程Future和Callable类示例分享
2021-09-02 09:49:37
Java对XML文件增删改查操作示例
2021-10-28 08:46:29
Java Collections.shuffle()方法案例详解
2023-11-24 15:53:16
Java包装类的概述与应用
2022-03-14 07:50:43
![](https://img.aspxhome.com/file/2023/0/91110_0s.png)
c# 开发语音识别程序
2022-03-23 04:55:57
![](https://img.aspxhome.com/file/2023/3/91313_0s.png)