How to make it happen Windows Control's Event in Code?

  • Thread starter Thread starter Jonathan Woods
  • Start date Start date
J

Jonathan Woods

Hi there,

I'm just wondering is there anyway possibly about windows control's
events make happen in code? Not in Form..

As if it is user click button on form during the execution of code

Just like custom event make it happen ... or some other ways?
private void doSomething()
{
//Some code...
btnButton.Click(null,null);
}
 
I think it's generally not a good idea to invoke a control's event from code
like this. When faced with the need to do this, I will put the guts of the
event handler into a separate method. The Click event handler becomes a
single line that calls the new method, and the new method can be called from
elsewhere in code. For one thing, if you end up removing the control, you
won't remove the method that your code is calling from somewhere else.

Rob
 
Back
Top