zoukankan      html  css  js  c++  java
  • ReadOnly TextEdit输入问题

        public class StringEventArgs : EventArgs
        {
            public String Value { get; set; }
        }
        public class ReadOnlyInputMgr
        {
            
            private Dictionary<int, String> _KeyValueDic =
                new Dictionary<int, string>() { 
                { 48, "0" }, { 49, "1" }, { 50, "2" }, { 51, "3" }, 
                {52,"4"},{53,"5"},{54,"6"},{55,"7"},{56,"8"},
                {57,"9"},{190,"."}
                };
            public EventHandler<StringEventArgs> OnDiameterInput;
            private StringBuilder _Buffer = new StringBuilder();
            public Boolean SuppressInput { get; set; }
            public ReadOnlyInputMgr()
            {
                SuppressInput = false;
            }
            public ReadOnlyInputMgr(TextEdit txt)
                : this()
            {
                txt.KeyDown += (s, e) =>
                {
                    this.In(e.KeyValue);
                };
                OnDiameterInput += (s, e) => 
                {
                    Console.WriteLine(e.Value);
                    SuppressInput = true;
                    txt.Text = e.Value;
                    SuppressInput = false;
                };
            }
            public void In(int keyValue)
            {
                if (SuppressInput) return;
                if (keyValue == 13)
                {
                    double d = 0.0;
                    if (double.TryParse(_Buffer.ToString(), out d))
                    {
                        if (OnDiameterInput != null)
                        {
                            OnDiameterInput(this,new StringEventArgs(){Value= _Buffer.ToString().Trim()});
                        }
                    }
                    _Buffer.Clear();
                }
                else
                {
                    if (_KeyValueDic.ContainsKey(keyValue))
                    {
                        _Buffer.Append(_KeyValueDic[keyValue]);
                    }
                    else
                    {
                        _Buffer.Clear();
                    }
                }
            }
        }
    View Code
  • 相关阅读:
    python 字典
    python 列表、元组 for 循环
    python字符串
    python之while 循环 格式化、运算符、编码
    Python变量命名的规范、if else 条件语句
    Linux文件管理-主题2
    Linux系统管理-主题1
    Linux操作系统零基础入门学习3
    CCF--二十四点
    第一个Python程序
  • 原文地址:https://www.cnblogs.com/wdfrog/p/12357755.html
Copyright © 2011-2022 走看看