Wiring Controls in Visual Basic, Controlling the Controls

孤街醉人 提交于 2019-12-02 06:51:23

Using an anonymous sub (VB2010 only) to write the event handler inline

Timer myTimer = New Timer
Button button = New Button
AddHandler button.Click,
    Sub(s As Object, e As EventArgs)
         ' can manipulate the Timer here 
         ' because it is captured in a closure     
         myTimer.Stop    
    End Sub

Adapted from here.

PS read more about closures from our very own Jared.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!