c# event and delegate question

Posted by user359562 on Stack Overflow See other posts from Stack Overflow or by user359562
Published on 2010-06-09T10:18:54Z Indexed on 2010/06/09 10:22 UTC
Read the original article Hit count: 124

Filed under:

I want to detach the custom event but could not detach. Please find below I am using -= to detach the event. I assume after this, TextChanged2 method should not be invoked as I have unregistered the event. Let me know if my understanding is wrong.

public delegate void TextChangedEventHandler1(object sender, TextBoxargs ta);
public event TextChangedEventHandler1 TextChanged1;
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.TextChanged1 -= new  TextChangedEventHandler1(TextChanged2);
            TextChanged2(sender, e);
        }
        public void TextChanged2(object sender, EventArgs e)
        { 
            textBox1.Text = textBox1.Text.ToUpper();
        }

© Stack Overflow or respective owner

Related posts about events