1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
- public partial class MaskedIDNumber : MaskedTextBox
- {
- public MaskedIDNumber()
- {
- InitializeComponent();
- }
- private string _strValue;
- /// <summary>
- /// 值
- /// </summary>
- public string StrValue
- {
- get
- {
- if (this.Text.Trim().Replace("-", "").Trim() != "")
- { _strValue = this.Text.Trim().Replace(" ", ""); }
- else
- { _strValue = this.Text.Trim().Replace("-", "").Trim(); }
- return _strValue;
- }
- set
- {
- _strValue = value;
- this.Text = _strValue;
- }
- }
- public MaskedIDNumber(IContainer container)
- {
- container.Add(this);
- InitializeComponent();
- this.Mask = "000000 00000000 000A";
- this.PromptChar = ' ';
- this.MouseClick += MaskedIDNumber_MouseClick;
- }
- void MaskedIDNumber_MouseClick(object sender, MouseEventArgs e)
- {
- if (this.StrValue.Length < 10)
- { this.ForCharMaskedTextBox(); }
- }
- /// <summary>
- /// 点击时在空值处获得光标
- /// </summary>
- private void ForCharMaskedTextBox()
- {
- char[] charList = this.Text.ToCharArray();
- bool isbl = true;
- for (int i = (charList.Length - 1); i >= 0; i--)
- {
- if (charList[i].ToString() != " ")
- {
- this.SelectionStart = i + 1;
- return;
- }
- if (i == 0)
- {
- if (isbl)
- { this.SelectionStart = 0; }
- }
- }
- }
- }
- }
|