這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)VB.NET中如何使用事件通道,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
濮陽網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),濮陽網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為濮陽上1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的濮陽做網(wǎng)站的公司定做!
C#代碼示例如下:
public delegate void showMsg
EventHandler(string msg);
class msg
{
public event showMsgEvent
Handler showMsgEvent;
public string execMsg(string msg){
if (showMsgEvent != null)
{
showMsgEvent(msg + "," +
DateTime.Now.ToString());}
return string.Empty;
}
}
===調(diào)用===
int i = 3;
msg[] myMsg;
private void button2_Click
(object sender, EventArgs e){
myMsg = new msg[i];
for(int j=0;j<i;j++)
{
myMsg[j]=new msg();
myMsg[j].showMsgEvent +=new
showMsgEventHandler(Form3_
showMsgEvent);}
}
void Form3_showMsgEvent (string msg)
{
MessageBox.Show(msg);
}
private void button3_Click
(object sender, EventArgs e){
for (int j = 0; j < i; j++)
{
myMsg[j].execMsg("good "
+ j.ToString());}
}
轉(zhuǎn)換后的VB.NET事件通道代碼:
Delegate Sub showMsgEventHandler
()Sub showMsgEventHandler
(ByVal msg As String)Class msgClass msg
Public name As String
Event msgEvent As showMsg
EventHandlerPublic Sub showMsg()Sub showMsg
(ByVal msg As String)MsgBox(msg + DateTime.Now.
ToString() + " ," + name)End Sub
End Class===調(diào)用===
Dim i As Integer = 0
Dim myContain As New List(Of msg)
Private Sub Button2_Click(
)Sub Button2_Click(ByVal sender
As System.Object, ByVal e As
System.EventArgs) Handles Button2.ClickFor i = 0 To 3 Step 1
Dim myMsg As New msg
myMsg.name = "name" & i.ToString()
myContain.Add(myMsg)
AddHandler myMsg.msgEvent,
New showMsgEventHandler(AddressOf
responseMsg)Next i
End Sub
Private Sub responseMsg()Sub
responseMsg(ByVal msg As String)MsgBox(msg)
End Sub
Private Sub Form1_Load()Sub Form1_Load
(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.LoadEnd Sub
Private Sub Button3_Click()Sub
Button3_Click(ByVal sender As
System.Object, ByVal e As System.
EventArgs) Handles Button3.ClickFor i = 0 To 3 Step 1
Dim myMsg As New msg
myMsg = myContain.Item(i)
myMsg.showMsg("good ")
Next i
End Sub
上述就是小編為大家分享的VB.NET中如何使用事件通道了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享文章:VB.NET中如何使用事件通道
網(wǎng)站鏈接:http://jinyejixie.com/article10/ipihdo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、響應(yīng)式網(wǎng)站、網(wǎng)站收錄、全網(wǎng)營銷推廣、Google、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)