views:

666

answers:

2

I have made a winforms application and in it i've implemented a custom richtextbox control. Now i'm refering it as a windows control (a dll file)in my project. In my program for the richtextbox i've written functionality inside it's textchanged event. Now i want to do some additional work which can happen only after the textchanged event is fired or in otherways once the text is added to the textbox. Something like i want to call a function foo() in the text_changedevent, but problem is it only calls foo and fails to process the underlying textchanged event. Any way in C# i can make it process the internal textchanged event first, and then look into my text changed event?

think of the scenario where i've written the code for mytextbox_textchanged

private void txt_code_TextChanged(object sender, EventArgs e)
    {
        //some code which will always be called whenever textchanged event occurs.
    }

Now i inherit this control in my project say MyApp1. here i have a label where i want to display the number of lines contained inside my textbox. So i'd write

private void my_inherited_txt_code_TextChanged(object sender, EventArgs e)
    {
        //code to update the label with my_inherited_txt_code.lines.length
    }

so my problem was, i first wanted the txt_code_TextChanged event to be called and then do the code written inside my_inherited_txt_code_TextChanged. Which was solved by writing

private void my_inherited_txt_code_TextChanged(object sender, EventArgs e)
    {
        base.OnTextChanged(e);
        MessageBox.Show("foo");
    }
A: 

I cant see why you shouldnt be able to call a method from the text_changed event? Do you get any errors or what happens exactly?

Moulde
+1  A: 

Do you mean:

protected override void OnTextChanged(EventArgs e)
{
    base.OnTextChanged(e);
    // your code here...
}
Marc Gravell
thanks. that was what i was looking for!
Anirudh Goel