WithEvents/Handles better than Remove/AddHandler?

前端 未结 3 2075
轮回少年
轮回少年 2020-12-20 16:35

From a memory point of view (remove an added handler after utilization, etc.), is WithEvents and Handles usage preferable to RemoveHandler

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 17:14

    It depends on what you're trying to achieve. If you have several event handlers which must handle events for various controls during the lifetime of a form/object then WithEvents and Handles is the easiest way to go. The language will do all of the dirty work for you in terms of setting up the event. On the other hand, if you tend to disconnect from events during the lifetime of the form, AddHandler and RemoveHandler are better options.

提交回复
热议问题