12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
- public partial class MaskedTextBoxEx : MaskedTextBox
- {
- public MaskedTextBoxEx()
- {
- InitializeComponent();
- }
- public MaskedTextBoxEx(IContainer container)
- {
- container.Add(this);
- InitializeComponent();
- this.MouseClick += MaskedTextBoxEx_MouseClick;
- }
- /// <summary>
- /// 鼠标点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void MaskedTextBoxEx_MouseClick(object sender, MouseEventArgs e)
- {
- ForCharMaskedTextBox();
- }
- /// <summary>
- /// 重写输入限制
- /// </summary>
- /// <param name="e"></param>
- protected override void OnKeyPress(KeyPressEventArgs e)
- {
- if (LYFZ.BLL.OtherCommonModel.IsQaJiaoChar(e.KeyChar))
- { e.Handled = true; }
- else
- { base.OnKeyPress(e); }
- }
- /// <summary>
- /// 点击时在空值处获得光标
- /// </summary>
- public void ForCharMaskedTextBox()
- {
- char[] charList = this.Text.Trim().ToCharArray();
- if (charList.Length > 0)
- {
- for (int i = (charList.Length - 1); i >= 0; i--)
- {
- if (i == 0)
- {
- if (charList[i].ToString() == " ")
- {
- this.SelectionStart = i;
- return;
- }
- }
- else
- {
- if (charList[i].ToString() != " ")
- {
- this.SelectionStart = i + 1;
- return;
- }
- }
- }
- }
- else { this.SelectionStart = 0; }
- }
- }
- }
|