码迷,mamicode.com
首页 > Windows程序 > 详细

wpf中文本框只能输入整数

时间:2019-06-17 17:33:14      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:wpf   ons   ||   color   ret   lse   oid   turn   txt   

 1 private void txtBarCodeNum_KeyUp(object sender, KeyEventArgs e)
 2         {
 3             TxtInt(sender as TextBox);
 4         }
 5 
 6         private void txtBarCodeNum_TextChanged(object sender, TextChangedEventArgs e)
 7         {
 8             TxtInt(sender as TextBox);
 9         }
10 
11         private void TxtInt(TextBox txt)
12         {
13             if (txt==null || string.IsNullOrEmpty(txt.Text))
14             {
15                 txt.Tag = "";
16                 return;
17             }
18             try
19             {
20                 txt.Text = txt.Text.Trim();
21                 txt.Tag = Convert.ToInt32(txt.Text); ;
22             }
23             catch
24             {
25                 if (txt.Tag==null)
26                 {
27                     txt.Text = "";
28                 }
29                 else
30                 {
31                     txt.Text = txt.Tag.ToString();
32                 }
33             }
34             txt.SelectionStart = txt.Text.Length;
35         }

 

wpf中文本框只能输入整数

标签:wpf   ons   ||   color   ret   lse   oid   turn   txt   

原文地址:https://www.cnblogs.com/DoNetCShap/p/11040714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!