zoukankan      html  css  js  c++  java
  • WPF文本框只允许输入数字和小数

    /// <summary>
            /// 限制文本框只允许输入小数
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void WaterTextBoxControl_PreviewKeyDown(object sender, KeyEventArgs e)
            {
                var textBox = sender as TextBox;

                if ((e.Key == Key.OemPeriod && textBox.Text.Contains(".")) || e.Key == Key.OemPeriod && string.IsNullOrWhiteSpace(textBox.Text))
                {
                    e.Handled = true;
                    return;
                };

                if (!((e.Key >= Key.D0 && e.Key <= Key.D9)
                    || e.Key == Key.Delete || e.Key == Key.Back || e.Key == Key.OemPeriod
                    || e.Key == Key.Tab || e.Key == Key.OemBackTab
                    || e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Up || e.Key == Key.Down)
                    || (e.KeyboardDevice.Modifiers == ModifierKeys.Control && e.Key == Key.A))
                {
                    if (e.KeyboardDevice.Modifiers != ModifierKeys.Control)
                    {
                        e.Handled = true;
                    }
                }
            }

    设置文本框的InputMethod.IsInputMethodEnabled="False" 文本框只允许英文模式

  • 相关阅读:
    PDO事务处理不能保持一致性
    Android开发中的SQLite事务处理
    Mysql安装
    IIS下https配置及安全整改
    exchang2010OWA主界面添加修改密码选项
    查阅文件技巧
    RHEL yum
    CentOS之——CentOS7安装iptables防火墙
    Linux修改主机名称
    Vmware虚拟机设置静态IP地址
  • 原文地址:https://www.cnblogs.com/JqkAman/p/12371169.html
Copyright © 2011-2022 走看看