It depends on what you're actually trying to do, as Viv mentioned, it may not be too clear from your description of what you're trying to accomplish.
>Is it ok from one control event call another control's event or it's better to have both call their own but reference an extra common function?When I first read your question, it sounded like you wanted code in one control's event handler to call the event handler of another control. Something like this:
private void MyTextBoxOne_Validated(object sender, System.EventArgs e)
{
this.MyTextBoxTwo_Validated(sender, e);
}
private void MyTextBoxTwo_Validated(object sender, System.EventArgs e)
{
}
This is obviously a no-no and I think Al thought your question was this, hence his answer.
But, then, in your reply to Viv:
>Or how would you approach the problem of having same code executed for the same event in different objects?It seems to me what you're actually asking is not what it seemed from your first question. Anyway, there's nothing wrong with having one event handler take care of an event for more than one control. Say I have several TextBoxes on my Form, but in the Validated event of each one, I want to do the exact same thing.
So, I'd have one MyTextBoxValidatedHandler, and each TextBox would have a delegate for that event handler. Something like this:
this.MyTextBoxOne.Validated() += new EventHandler(this.MyTextBoxValidatedHandler);
this.MyTextBoxTwo.Validated() += new EventHandler(this.MyTextBoxValidatedHandler);
this.MyTextBoxThree.Validated() += new EventHandler(this.MyTextBoxValidatedHandler);
And the event handler would be the usual:
private void MyTextBoxValidatedHandler(object sender, System.EventArgs e)
{
}
HTH,
~~Bonnie