黄学彪
2019-11-04 c7698e163e43cea9e7f8ee45f8e3f91c9265cca4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色
    /// </summary>
    public class TextInputExControl : TextInputBase
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 输入结束的事件
        /// </summary>
        public Action FinishInputEvent = null;
        /// <summary>
        /// 最大输入长度(目前只针对按下回车键时进行检测,超过时,不会调用FinishInputEvent)
        /// </summary>
        public int MaxByte = 0;
        /// <summary>
        /// 文本是否为黑色字体
        /// </summary>
        private bool IsTextBlack = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public TextInputExControl(int i_Width, int i_Height, bool real = false)
        {
            this.InitSize(i_Width, i_Height, real);
            this.TextColor = UserCenterColor.Current.TextGrayColor3;
 
            this.TextChangeEventHandler += this.TextChangeEvent;
            this.EditorEnterAction += this.EditorEnterEvent;
        }
 
        /// <summary>
        /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="real">是否计算真实值</param>
        public TextInputExControl(int i_Width, bool real = false)
        {
            this.InitSize(i_Width, real);
            this.TextColor = UserCenterColor.Current.TextGrayColor3;
 
            this.TextChangeEventHandler += this.TextChangeEvent;
            this.EditorEnterAction += this.EditorEnterEvent;
        }
 
        #endregion
 
        #region ■ 输入事件___________________________
 
        /// <summary>
        /// 输入完成事件
        /// </summary>
        /// <param name="view"></param>
        private void EditorEnterEvent(View view)
        {
            if (this.MaxByte != 0)
            {
                if (Encoding.UTF8.GetBytes(this.Text.Trim()).Length > this.MaxByte)
                {
                    //输入内容过长,最大{0}字节
                    string msg = Language.StringByID(R.MyInternationalizationString.uInputContentIsOverLengthMsg);
                    msg.Replace("{0}", this.MaxByte.ToString());
                    var contr = new ShowMsgControl(ShowMsgType.Error, msg);
                    contr.Show();
                    return;
                }
            }
            this.TextColor = UserCenterColor.Current.TextGrayColor3;
            this.IsTextBlack = false;
            this.FinishInputEvent?.Invoke();
        }
 
        /// <summary>
        /// 值改变事件
        /// </summary>
        /// <param name="view"></param>
        /// <param name="value"></param>
        private void TextChangeEvent(View view, string value)
        {
            if (this.IsTextBlack == true || this.Foucs == false)
            {
                return;
            }
            this.IsTextBlack = true;
            this.TextColor = UserCenterColor.Current.TextColor1;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 控件销毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.FinishInputEvent = null;
 
            base.RemoveFromParent();
        }
 
        #endregion
    }
}