using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter { /// /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色 /// public class TextInputExControl : TextInputBase { #region ■ 变量声明___________________________ /// /// 输入结束的事件 /// public Action FinishInputEvent = null; /// /// 最大输入长度(目前只针对按下回车键时进行检测,超过时,不会调用FinishInputEvent) /// public int MaxByte = 0; /// /// 文本是否为黑色字体 /// private bool IsTextBlack = false; #endregion #region ■ 初始化_____________________________ /// /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色 /// /// 宽度 /// 高度 /// 是否计算真实值 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; } /// /// 特殊的输入框,初始状态和输入完成后,字体变为灰色,输入时为黑色 /// /// 宽度 /// 是否计算真实值 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 ■ 输入事件___________________________ /// /// 输入完成事件 /// /// 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(); } /// /// 值改变事件 /// /// /// 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 ■ 一般方法___________________________ /// /// 控件销毁 /// public override void RemoveFromParent() { this.FinishInputEvent = null; base.RemoveFromParent(); } #endregion } }