public partial class R_TextBox : TextBox
{
public R_TextBox()
{
InitializeComponent();
}
string strleng = "";
private int TDigit = 10;
[Browsable(true), Category("限定位数文本框"), Description("位数设置")]
public int Digit
{
get { return TDigit; }
set
{
TDigit = value;
}
}
private void R_TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
strleng = Text + e.KeyChar.ToString();
if (strleng.Length > Digit)
{
if (this.SelectedText.Length == 0)
e.Handled = true;
}
}
}
1.写好后组件类后,拖动到Form上。
2.显示组件的属性窗口,看下组件新添加的属性。