How To get code to be execute of button click in runtime anywhere

Suppose name of button is button1
then we need to do as folllowing
button1.PerformClick();
this will execute code under click event of button1