扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
1 Public Class Form1Class Form1 2 3 Inherits System.Windows.Forms.Form 4 5 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button4.Click 6 7 Select Case CType(sender, Button).Name 8 9 Case "Button1" 10 11 MessageBox.Show("你点击了Button1!", "委托提示", MessageBoxButtons.OK) 12 13 Case "Button2" 14 15 MessageBox.Show("你点击了Button2!", "委托提示", MessageBoxButtons.OK) 16 17 Case "Button3" 18 19 MessageBox.Show("你点击了Button3!", "委托提示", MessageBoxButtons.OK) 20 21 Case "Button4" 22 23 MessageBox.Show("你点击了Button4!", "委托提示", MessageBoxButtons.OK) 24 25 End Select 26 27 End Sub 28 29 Private Sub Button2_Click()Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 30 31 MessageBox.Show("Button2的Click事件,注意执行顺序!", "委托提示", MessageBoxButtons.OK) 32 33 End Sub 34 35 Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 36 37 Dim Demohandler1 As DemoHandler 38 39 Demohandler1 = AddressOf Button1_Click 40 41 Demohandler1.Invoke(sender, e) 42 43 Dim Demohandler2 As DemoHandler 44 45 Demohandler2 = AddressOf Button2_Click 46 47 Demohandler2(sender, e) 48 49 50 51 End Sub 52 53 Private Sub Button4_Click()Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 54 55 End Sub 56 57 Private Sub Button5_Click()Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 58 59 End Sub 60 61 Private Sub Form1_DoubleClick()Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick, Button5.Click 62 63 If TypeOf sender Is Button Then 64 65 If MessageBox.Show("你确定退出吗?", "退出提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.Yes Then 66 67 Me.Close() 68 69 Else : Exit Sub 70 71 End If 72 73 Else : Me.Close() 74 75 End If 76 77 End Sub 78 79End Class 80 |
语 句 | 释 义 |
Dim Demohandler1 As DemoHandler | 定义一个DemoHandler委托的实例,DemoHandler可以换成 EventHandler |
Demohandler1 = AddressOf Button1_Click | AddressOf可以认为就是将该委托和Button1_Click绑定 |
Demohandler1.Invoke(sender, e) | 显式使用委托的Invoke方法调用事件处理程序 |
Dim Demohandler2 As DemoHandler | 定义一个DemoHandler委托的实例,DemoHandler2 |
Demohandler2 = AddressOf Button2_Click | 同上AddressOf |
Demohandler2(sender, e) | 隐式使用委托的Invoke方法调用事件处理程序 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者