WPF TextBox输入限制,只能输入数字,字母

        Key preKey;
        private void Tb_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            bool isNumber = e.Key >= Key.D0 && e.Key <= Key.D9 || e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9;
            bool isLetter = e.Key >= Key.A && e.Key <= Key.Z && preKey != Key.LeftCtrl && preKey != Key.RightAlt && preKey != Key.LeftAlt && preKey != Key.RightAlt;
            bool isCtrlA = e.Key == Key.A && (preKey == Key.LeftCtrl || preKey == Key.RightCtrl);
            bool isCtrlV = e.Key == Key.V && (preKey == Key.LeftCtrl || preKey == Key.RightCtrl);
            bool isBack = e.Key == Key.Back;
            bool isLeftOrRight = e.Key == Key.Left || e.Key == Key.Right;
            bool isUpOrDown = e.Key == Key.Up || e.Key == Key.Down;
            
            if (isNumber || isCtrlA || isCtrlV || isBack || isLeftOrRight || isUpOrDown)
                e.Handled = false;
            else
                e.Handled = true;
            preKey = e.Key;
        } 

  

WPF TextBox输入限制,只能输入数字,字母

上一篇:springsecurity集成jwt时JwtTokenFilter的位置


下一篇:windows平台部署.netcore和vue项目