• 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
  • 相关阅读:
    struts2笔记之if控制标签
    struts2标签之iterator遍历集合
    struts2获得session和request
    数据库操作语句
    weixinapp api
    struts2笔记之tree标签输出树
    struts2笔记之整合Tiles
    C++中的符号
    JSP布局相关使用
    5.Github仓库
  • 原文地址:https://www.cnblogs.com/wdfrog/p/12357755.html
Copyright © 2020-2023  润新知