Link to home
Start Free TrialLog in
Avatar of gvector1
gvector1

asked on

Change Monitor

Is there any simple ways to monitor a forms control and all of its subcontrols for changes made to the containing text.
Ex. A form has a tabcontrol containing multiple textboxes.  If any one of the textboxes values change, I would like to set a boolean variable accordingly.  Is there any approaches that are suggested to this???????

Thanks,
Kendal
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

You can use the OnChange event, which can be set through the properties on the form or you can add it... you can also forward the event... for example

MyForm has YourForm has YourText....

public class MyForm : From {
    private bool hasTextChanged = false;

    public MyForm() {
        Form YourForm = new YourForm();
        YourForm.OnTextChanged += new EventHandler( YourForm_TextChanged );
    }
    private void YourForm_TextChanged( object sender, EventArgs args ) {
        hasTextChanged = true;
    }
}

HTH
Avatar of gvector1

ASKER

Doesn't the ontextchanged event only get triggered if the text property of the form is changed??????  My specific incident has a tabcontrol.  If any of the textboxes, belonging to the tabcontrol, text properties changes I would like to set the boolean variable.  Because of your suggestion, I though of having a single event and pointing each textboxes textchanged event to that one event.  Do you have any other suggestions??????

Thanks,
Kendal
That is where I was leading to...  Basically when you create the tabcontrol you could register for the event at that time... so the same event handler would be listening to all the possible events for the textchange.
Wouldn't I still have to point each textbox's textchanged event to that one event?????????
ASKER CERTIFIED SOLUTION
Avatar of NipNFriar_Tuck
NipNFriar_Tuck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, so for instance.  On the form designer, for each textbox, I set the OnTextChange event to actually trigger the MyEventHandler method.  Is that correct?????
Yes, I believe that that should work...
Thanks for the assistance.
The points are yours.

Thanks,
Kendal