• 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" 文本框只允许英文模式

  • 相关阅读:
    postgresql修改postgres用户密码
    centos7 安装netstat命令工具
    sqlplus、lsnrctl命令工具不可用(libclntsh.so.11.1)
    oracle修改数据文件目录
    oracle数据库主主复制
    Spring--quartzJob配置
    TimerTask--spring配置
    SSM+Apache shiro--ehcache缓存清理
    SSM+Apache shiro--自定义realm
    ssm+Apache shiro--配置文件
  • 原文地址:https://www.cnblogs.com/JqkAman/p/12371169.html
Copyright © 2020-2023  润新知