zoukankan      html  css  js  c++  java
  • wpf中文本框只能输入整数

     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         }
  • 相关阅读:
    手工测试
    测试理论
    MySQL常用语法
    Linux设置静态ip
    设计模式
    Shiro
    TreeSet和TreeMap
    UDP和反射
    Linux归纳
    Spring+SpringMVC+Mybatis整合
  • 原文地址:https://www.cnblogs.com/DoNetCShap/p/11040714.html
Copyright © 2011-2022 走看看