首页 > Windows开发 > 详细

WPF TextBox限制只能输入数字

时间:2021-01-18 11:32:18      阅读:35      评论:0      收藏:0      [点我收藏+]

WPF TextBox限制只能输入数字

  private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            TextBox txt = sender as TextBox;

            // 过滤按键
            if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9))
            {
                e.Handled = false;
            }
            else if (((e.Key >= Key.D0 && e.Key <= Key.D9)))
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

WPF TextBox限制只能输入数字

原文:https://www.cnblogs.com/blogs0104/p/14291475.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!