| | |
| | | /// <summary>
|
| | | /// 验证码控件
|
| | | /// </summary>
|
| | | public class VerificationCodeControl : FrameLayout
|
| | | public class VerificationCodeControl : NormalFrameLayout
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | |
| | | /// </summary>
|
| | | public Action<string> FinishInputEvent = null;
|
| | | /// <summary>
|
| | | /// 密码输入类型
|
| | | /// 密码输入类型(它与NumberInputOnly不共存)
|
| | | /// </summary>
|
| | | public bool SecureTextEntry = false;
|
| | | /// <summary>
|
| | | /// 输入键盘指定为数字键盘(默认为true,它与SecureTextEntry不共存)
|
| | | /// </summary>
|
| | | public bool NumberInputOnly = true;
|
| | | /// <summary>
|
| | | /// 验证码长度
|
| | | /// </summary>
|
| | |
| | | frameCode.X = i * Application.GetRealWidth(115 + 49);
|
| | | frameCode.Width = Application.GetRealWidth(115);
|
| | | frameCode.Height = Application.GetRealHeight(104);
|
| | | frameCode.Radius = 6;
|
| | | frameCode.Radius = (uint)Application.GetRealHeight(17);
|
| | | frameCode.BorderWidth = 1;
|
| | | frameCode.BorderColor = UserCenterColor.Current.TextFrameColor;
|
| | | this.AddChidren(frameCode);
|
| | |
| | | if (SecureTextEntry == true)
|
| | | {
|
| | | txtCode.SecureTextEntry = true;
|
| | | }
|
| | | else if (NumberInputOnly == true)
|
| | | {
|
| | | txtCode.IsNumberKeyboardType = true;
|
| | | }
|
| | | txtCode.Name = i.ToString();
|
| | | txtCode.TextAlignment = TextAlignment.Center;
|
| | |
| | | }
|
| | | if (e.Focus == true)
|
| | | {
|
| | | //自动焦点选择前面的空白位置
|
| | | //if (txtCode.Text == string.Empty)
|
| | | //{
|
| | | // for (int i = 0; i < this.CodeLenth; i++)
|
| | | // {
|
| | | // if (dicCodeControls[i].Text == string.Empty)
|
| | | // {
|
| | | // dicCodeControls[i].FoucsChanged -= this.TxtCode_FoucsChangedEvent;
|
| | | // dicCodeControls[i].Parent.BorderColor = UserCenterColor.Current.TextFrameSelectColor;
|
| | | // dicCodeControls[i].Foucs = true;
|
| | | // dicCodeControls[i].FoucsChanged += this.TxtCode_FoucsChangedEvent;
|
| | | // return;
|
| | | // }
|
| | | // }
|
| | | //}
|
| | | txtCode.Parent.BorderColor = UserCenterColor.Current.TextFrameSelectColor;
|
| | | #if Android
|
| | | txtCode.SetSelectionEnd(); |
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | if (textValue.Length == this.CodeLenth)
|
| | | {
|
| | | dicCodeControls[this.CodeLenth - 1].Foucs = true;
|
| | | #if Android
|
| | | //光标至于最后
|
| | | dicCodeControls[this.CodeLenth - 1].SetSelectionEnd();
|
| | | #endif
|
| | | for (int i = 0; i < this.CodeLenth; i++)
|
| | | {
|
| | | //先移除事件
|
| | |
| | | if (dicCodeControls.ContainsKey(index + 1) == true)
|
| | | {
|
| | | dicCodeControls[index + 1].Foucs = true;
|
| | | #if Android
|
| | | //光标至于最后
|
| | | dicCodeControls[index + 1].SetSelectionEnd();
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | #if Android
|
| | | //光标至于最后
|
| | | txtCode.SetSelectionEnd();
|
| | | #endif
|
| | | //最后一位输入完成,校验验证码
|
| | | string code = string.Empty;
|
| | | for (int i = 0; i < this.CodeLenth; i++)
|
| | |
| | | if (dicCodeControls.ContainsKey(index - 1) == true)
|
| | | {
|
| | | dicCodeControls[index - 1].Foucs = true;
|
| | | #if Android
|
| | | //光标至于最后
|
| | | dicCodeControls[index - 1].SetSelectionEnd();
|
| | | #endif
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 清空输入的值
|
| | | /// </summary>
|
| | | public void ClearInputValue()
|
| | | {
|
| | | foreach (var inputText in this.dicCodeControls.Values)
|
| | | {
|
| | | //先移除事件
|
| | | inputText.TextChangeEventHandler -= TxtCode_TextChangeEvent;
|
| | | //赋值
|
| | | inputText.Text = string.Empty;
|
| | | inputText.TextChangeEventHandler += TxtCode_TextChangeEvent;
|
| | | }
|
| | | dicCodeControls[0].Foucs = true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 控件摧毁___________________________
|