WPF 怎么让Textbox只能输入数字?
第一步 禁掉输入法:
<Window x:Class="WpfModelViewApplication1.Views.MainView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"Title="Main Window" Height="400" Width="800"><Grid x:Name="grid1"><TextBox x:Name="tb" Width="100" HorizontalAlignment="Right" Margin="0,164,122,128" input:InputMethod.IsInputMethodEnabled="False"/></Grid>
</Window>
第二步 采用正则表达式:
<Window x:Class="WpfModelViewApplication1.Views.MainView"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:input="clr-namespace:System.Windows.Input;assembly=PresentationCore"Title="Main Window" Height="400" Width="800"><Grid x:Name="grid1"><TextBox x:Name="tb" Width="100" HorizontalAlignment="Right" Margin="0,164,122,128" PreviewTextInput="tb_PreviewTextInput" input:InputMethod.IsInputMethodEnabled="False"/></Grid>
</Window>
cs后台代码:
//using System.Text.RegularExpressions;private void tb_PreviewTextInput(object sender, TextCompositionEventArgs e)
{Regex re = new Regex("[^0-9.-]+");e.Handled = re.IsMatch(e.Text);
}
WPF 怎么让Textbox只能输入数字?相关推荐
- wpf怎么让Textbox只能输入数字?
只需要两步: 1.禁掉输入法: <Window x:Class="WpfModelViewApplication1.Views.MainView" xmlns=&qu ...
- WPF TextBox只能输入数字
关于WPF TextBox只能输入数字并不是一个很难的功能,网上许多的实现方式都是通过将String类型转换为Int32类型来进行判断的,自从对了Clr Via C#这本书以后就对拆装箱操作产生了恐惧 ...
- 限制文本框(TextBox)只能输入数字(VB6代码)
在一些要求只允许输入数值的场合,就用得上了. 基本思路是,先在文本框的keyPress事件里过滤键盘输入,再使用子类化将粘贴剪切等剪贴板操作吃掉. 窗体frmMain.frm内代码(窗体包含一个文本框 ...
- TextBox只能输入数字
Asp.net TextBox只能输入数字 <asp:textbox id="TextBox1" οnkeyup="if(isNaN(value))execComm ...
- 【WinForm】设置控件里面的所有TextBox只能输入数字
设置控件里面的所有TextBox只能输入数字 回顾 [WinForm]TextBox只能输入数字 只能输入整数 private static void tb_KeyPress(object sende ...
- WinForm TextBox 只能输入数字
在Winform(C#)中要实现限制Textbox只能输入数字,一般的做法就是在按键事件中处理,判断keychar的值.限制只能输入数字,小数点,Backspace,del这几个键.数字0~9所对应的 ...
- 【WinForm】TextBox只能输入数字
只能输入整数 方法一 private void tb_KeyPress(object sender, KeyPressEventArgs e) {//如果输入的不是退格和数字,则屏蔽输入if (!(e ...
- Asp.net控制TextBox只能输入数字
方法一: private void tBox_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 0x20) e.KeyCh ...
- Asp.net TextBox只能输入数字
<asp:textbox id="TextBox1" οnkeyup="if(isNaN(value))execCommand('undo')" runa ...
最新文章
- Ubuntu 14.04 64bit上安装有道词典Linux版本
- WebAssembly 系列(五)为什么 WebAssembly 更快?
- Leetcode 118. 杨辉三角 (每日一题 20210901)
- 让图片算好高宽再显示
- c 和 java 差异_java和C/C++的差异是什么
- cnn stride and padding_彻底搞懂CNN中的卷积和反卷积
- Android应用开发中三种常见的图片压缩方法
- 计算机网络知识点总结谢,《计算机网络基础》复习提纲_谢(5)版-课堂教案
- jquery删除空图片错误图片,$('img[src=]').remove();
- 1.nagios服务端安装
- php.ini – 配置文件详解
- 安装Python第三方库的基本方法
- fiddler抓包教程
- SPSS篇—方差分析
- Unity3d中XML的解析
- CTSC 2018 简要题解
- 国内外网站空间优劣势
- dxwebsetup 解决一些dll缺少的问题
- 2019, XII Samara Regional Intercollegiate Programming Contest 解题报告
- 计算机专业刊头,浅谈报纸版面在电脑排版中的美学应用