兩個(gè)參數(shù):一個(gè)是數(shù)組名,一個(gè)是傳遞的長(zhǎng)度
10年積累的成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先制作網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有宜秀免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
Function thename(ByVal imgFrom As Image) As String
thename = imgFrom.Name
End Function
Private Sub Image1_Click()
MsgBox thename(Image1)
End Sub
委托三個(gè)步驟
1、聲明委托 用Delegate 聲明一個(gè)委托 類型 參數(shù)要和 被委托的方法一樣 例如 Delegate Function a(byval x as string) as string
2、實(shí)例化委托 dim t as new a(AddressOf Function Name)
3.通過(guò) t(參數(shù)) 或者 t.Invoke(參數(shù)調(diào)用委托)
示例:
Module module1
Delegate Function a(ByVal x As Integer, ByVal y As Integer) As Integer '聲明委托類型 委托可以使一個(gè)對(duì)象調(diào)用另一個(gè)對(duì)象的方法
Function sum(ByVal x As Integer, ByVal y As Integer) As Integer
Return (x + y)
End Function
Sub main()
Dim d As New a(AddressOf sum) '實(shí)例化委托
Dim s = 0
s = d.Invoke(1, 2) '執(zhí)行委托
Console.WriteLine(s.ToString())
s = d(1, 2) '執(zhí)行委托
Console.WriteLine(s.ToString())
MsgBox("")
End Sub
End Module
線程結(jié)束后利用委托生成事件返回,線程應(yīng)用包括傳入和傳出參數(shù)。
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 = "測(cè)試"
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)
Me._result = value
End Sub
End Class
網(wǎng)頁(yè)名稱:包含vb.net委托參數(shù)的詞條
標(biāo)題網(wǎng)址:http://jinyejixie.com/article16/dosdedg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、App設(shè)計(jì)、ChatGPT、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容