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
|
}
|
}
|