自定义了一个新控件:label和textbox的组合控件。 为其添加了的属性中有一个是MaxLength(最大字符数)。
现 定义两个事件: MaxLengthChanged,最大字符数改变时触发。 MaxLengthArrived,新控件中的字符数已达MaxLength时触发。第一个事件:我在项目中添加了个TextBox用于用户设置新长度(默认长度为MaxLength=10),和一个Button按钮提交:
if(txtNewLength.Text.Length!=0)
ctlLabelTextBox1.MaxLength = Convert.ToUInt32(txtNewLength.Text.Trim().ToString());在自定义控件的属性MaxLength中我调用了事件的处理方法:
public uint MaxLength
{
get
{// mLength已定义为uint
return mLength;
}
set
{
if (mLength != value)
{
mLength = value;
if (MaxLengthChanged != null)
MaxLengthChanged(this, new EventArgs());
} textBox1.MaxLength = (int)mLength;
}
}
处理完成。事件2 MaxLengthArrived 怎么处理? 在何处处理? 我想在新控件的Load事件中检测处理却不对:private void ctlLabelTextBox_Load(object sender, EventArgs e)
{
label1.Text = this.Name;
this.Height = textBox1.Height > label1.Height ? textBox1.Height : label1.Height;
MoveControls(); if(textBox1.MaxLength==textBox1.Text.Length)
if (MaxLengthArrived != null)
MaxLengthArrived(this, new EventArgs());
}大家给我点帮助。
现 定义两个事件: MaxLengthChanged,最大字符数改变时触发。 MaxLengthArrived,新控件中的字符数已达MaxLength时触发。第一个事件:我在项目中添加了个TextBox用于用户设置新长度(默认长度为MaxLength=10),和一个Button按钮提交:
if(txtNewLength.Text.Length!=0)
ctlLabelTextBox1.MaxLength = Convert.ToUInt32(txtNewLength.Text.Trim().ToString());在自定义控件的属性MaxLength中我调用了事件的处理方法:
public uint MaxLength
{
get
{// mLength已定义为uint
return mLength;
}
set
{
if (mLength != value)
{
mLength = value;
if (MaxLengthChanged != null)
MaxLengthChanged(this, new EventArgs());
} textBox1.MaxLength = (int)mLength;
}
}
处理完成。事件2 MaxLengthArrived 怎么处理? 在何处处理? 我想在新控件的Load事件中检测处理却不对:private void ctlLabelTextBox_Load(object sender, EventArgs e)
{
label1.Text = this.Name;
this.Height = textBox1.Height > label1.Height ? textBox1.Height : label1.Height;
MoveControls(); if(textBox1.MaxLength==textBox1.Text.Length)
if (MaxLengthArrived != null)
MaxLengthArrived(this, new EventArgs());
}大家给我点帮助。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货