//输入的字符进行大写格式化(只允许输入字母)
public class LetterBox : RadTextBox
{
#region ToUpper
public enum ToUppers
{
False,
True,
}
private ToUppers to_Upper;
[DefaultValue(ToUppers.False)]
public ToUppers To_Upper
{
get
{
return to_Upper;
}
set
{
to_Upper = value;
}
}
#endregion
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{
base.OnKeyPress(e);
SetStandard(e);
}
private void SetStandard(System.Windows.Forms.KeyPressEventArgs e)
{
//只允许输入字母
Regex regex = new Regex("^[a-zA-Z]");
MatchCollection mc = regex.Matches(e.KeyChar.ToString());
foreach (Match ma in mc)
{
e.Handled = false;
return;
}
e.Handled = true;
}
protected override void OnTextChanged(EventArgs e)
{
base.OnTextChanged(e);
if (ToUppers.True.ToString() == To_Upper.ToString())
{
this.Text = this.Text.ToUpper();
this.Select(Text.Length, 0);
}
}
}