vb.net委托参数 vbnet function

vb.net 如何传递类参数线程结束后利用委托生成事件返回 , 线程应用包括传入和传出参数 。
Public Delegate Sub ThreadCallback(value As ThreadResult)
Public Class Form1
Private WithEvents _th_1 As Thread_1
Protected Overrides Sub OnLoad(e As System.EventArgs)
Dim value As ThreadObject
value.Index = 1
Me._th_1 = New Thread_1(Me)
Me._th_1.Run(value)
MyBase.OnLoad(e)
End Sub
Private Sub Thread_1_End(sender As Object, e As ThreadEventArgs) Handles _th_1.ThreadEnd
Me.TextBox1.Text = e.Result.Text
End Sub
End Class
Public Class Thread_1
Public Event ThreadEnd(sender As Object, e As ThreadEventArgs)
Private _control As Control
Sub New(control As Control)
Me._control = control
End Sub
Public Sub Run(value As Object)
Dim th As New Threading.Thread(AddressOf ThreadProc)
th.Start(value)
End Sub
Private Sub ThreadProc(obj As Object)
Dim value As ThreadObject = CType(obj, ThreadObject)
Dim result As ThreadResult = Nothing
If value.Index = 1 Then result.Text = "测试"
Dim callback As New ThreadCallback(AddressOf ThreadInvoke)
_control.Invoke(callback, result)
End Sub
Private Sub ThreadInvoke(value As ThreadResult)
RaiseEvent ThreadEnd(Me, New ThreadEventArgs(value))
End Sub
End Class
Public Structure ThreadObject
Public Index As Integer
'Public Rect As Rectangle
End Structure
Public Structure ThreadResult
Public Text As String
'Public Rect As Rectangle
End Structure
Public Class ThreadEventArgs
Inherits System.EventArgs
Private _result As ThreadResult
Public ReadOnly Property Result As ThreadResult
Get
Return _result
End Get
End Property
Sub New(value As ThreadResult)
【vb.net委托参数 vbnet function】Me._result = value
End Sub
End Class
vb.net 给委托的函数传递参数两个参数vb.net委托参数:一个是数组名,一个是传递vb.net委托参数的长度
Function thename(ByVal imgFrom As Image) As String
thename = imgFrom.Name
End Function
Private Sub Image1_Click()
MsgBox thename(Image1)
End Sub
vb.net 中在模块(module)里如何实现委托委托三个步骤
1、声明委托用Delegate 声明一个委托 类型参数要和 被委托vb.net委托参数的方法一样例如Delegate Function a(byval x as string)as string
2、实例化委托dimt as new a(AddressOfFunction Name)
3.通过 t(参数)或者t.Invoke(参数调用委托)
示例vb.net委托参数:
Module module1
Delegate Function a(ByVal x As Integer, ByVal y As Integer) As Integer'声明委托类型 委托可以使一个对象调用另一个对象vb.net委托参数的方法
Function sum(ByVal x As Integer, ByVal y As Integer) As Integer
Return (xy)
End Function
Sub main()
Dim d As New a(AddressOf sum)'实例化委托
Dim s = 0
s = d.Invoke(1, 2)'执行委托
Console.WriteLine(s.ToString())
s = d(1, 2)'执行委托
Console.WriteLine(s.ToString())
MsgBox("")
End Sub
End Module
vb.net委托参数的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于vbnet function、vb.net委托参数的信息别忘了在本站进行查找喔 。

    推荐阅读