G
Guest
While developing on windows forms, I found that most forms events (e.g. Load, KeyPress, MouseMove, LostFocus, etc....) have the equivalent virtual functions in the form of OnXXXX which can be overwritten. If I want to handle the KeyPress event, is it recommended to create an event handler in the constructor,
this.KeyPress += new KeyPressEventHandler(form1_KeyPress);
or to override the OnKeyPress virtual function?
I have tested both ways and didn't find any substantial differences between them. Is there any guideline to follow on which method to use?
this.KeyPress += new KeyPressEventHandler(form1_KeyPress);
or to override the OnKeyPress virtual function?
I have tested both ways and didn't find any substantial differences between them. Is there any guideline to follow on which method to use?