0
点赞
收藏
分享

微信扫一扫

C#编写组件类TextBox


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.显示组件的属性窗口,看下组件新添加的属性。

C#编写组件类TextBox_开发语言

 

举报

相关推荐

0 条评论