自定义了一个新控件: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());
        }大家给我点帮助。

解决方案 »

  1.   

    ctlLabelTextBox这个控件的textchange中判断吧
      

  2.   

    新控件ctlLabelTextBox 的Event列表中没有 textchanged 事件 
      

  3.   

    你的控件里不是由于label和textbox的组合的吗,textbox的textchanged 事件,发生的时候检查字符数
      

  4.   

    在TextBox的TextChanged的中检测处理 成功了。 谢谢 tcshen0。 严重表示感谢