How to add an event to a UserControl in C#?

后端 未结 6 2281
一向
一向 2020-11-27 05:04

I have a UserControl which contains 3 labels. I want to add an event for it, which occurs when the text of one of the labels changed.
I am using Visual Studio 2010

6条回答
  •  孤街浪徒
    2020-11-27 05:17

    public delegate void TextChangedEventHandler(object sender, EventArgs e);
    public event TextChangedEventHandler LabelTextChanged;
    
    // ...
    
    protected void MyTextBox_TextChanged(object sender, EventArgs e)
    {
        if (LabelTextChanged != null) {
            LabelTextChanged(this, e);
        }
    }
    

提交回复
热议问题