vb.net委托简单研究

前端之家收集整理的这篇文章主要介绍了vb.net委托简单研究前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@1.委托传参一
'stpe1 声明一个委托
Delegate Sub DelegateHandler(ByVal str As String)

@H_403_0@ Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("button2")

@H_403_0@ ' step2 New 出一个委托并指定委托方法
Dim dh As DelegateHandler = New DelegateHandler(AddressOf invokes) 'invokes为方法
' step3 调用invoke
Me.Invoke(dh,New Object() {"abc"})
End Sub

@H_403_0@ Private Sub invokes(ByVal n As String)
MsgBox(n)
End Sub

@H_403_0@
2.简单指定事件非传参
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
Dim pb As PictureBox = New PictureBox()
pb.Image = Image.FromFile("D:/vbNet/card/card/bin/Debug/a111.bmp")
pb.Width = 71
pb.Height = 96
pb.Left = 500
pb.Top = 500

@H_403_0@ Me.Controls.Add(pb)
AddHandler pb.Click,AddressOf pb_Click

@H_403_0@ End Sub

@H_403_0@ Public Sub pb_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)
MsgBox(sender.ToString)
End Sub

@H_403_0@3焦点控件
Public Sub pb_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)
MsgBox(Me.ActiveControl.Name)
End Sub

@H_403_0@4.循环取动态生成控件
Dim picBox As Object

@H_403_0@ For Each picBox In Me.Controls
If TypeOf picBox Is PictureBox Then
If picBox.Name = "a111" Then
MsgBox(picBox.Name)
End If
End If
Next

@H_403_0@5.指定事件并传参二
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
Dim pb As PictureBox = New PictureBox()
pb.Image = Image.FromFile("D:/vbNet/card/card/bin/Debug/a111.bmp")
pb.Width = 71
pb.Height = 96
pb.Left = 500
pb.Top = 500
pb.Name = "a111"
Me.Controls.Add(pb)
AddHandler pb.Click,AddressOf pb_Click
End Sub

@H_403_0@ Public Sub pb_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Dim pb As PictureBox = sender MsgBox(pb.Name) MsgBox(pb.Left) MsgBox(pb.Top) End Sub

原文链接:https://www.f2er.com/vb/262063.html

猜你在找的VB相关文章