VB.NET事件通道的实现,可以通过多个类的操作来进行实现。对于初学者来说,这一技巧的应用往往会给他们在实际应用中带来一定的麻烦。下面就为大家详细解读一下具体的操作步骤,以方便大家参考学习。
成都创新互联是一家集网站建设,三门峡企业网站建设,三门峡品牌网站建设,网站定制,三门峡网站建设报价,网络营销,网络优化,三门峡网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。
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;
- }
- }
- ===调用===
- int i = 3;
- msg[] myMsg;
- private void button2_Click
(object sender, EventArgs e)- {
- myMsg = new msg[i];
- for(int j=0;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());- }
- }
转换后的VB.NET事件通道代码:
- Delegate Sub showMsgEventHandler
()Sub showMsgEventHandler
(ByVal msg As String)- Class msgClass msg
- Public name As String
- Event msgEvent As showMsg
EventHandler- Public Sub showMsg()Sub showMsg
(ByVal msg As String)- MsgBox(msg + DateTime.Now.
ToString() + " ," + name)- End Sub
- End Class===调用===
- 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.Click- For 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.Load- End Sub
- Private Sub Button3_Click()Sub
Button3_Click(ByVal sender As
System.Object, ByVal e As System.
EventArgs) Handles Button3.Click- For i = 0 To 3 Step 1
- Dim myMsg As New msg
- myMsg = myContain.Item(i)
- myMsg.showMsg("good ")
- Next i
- End Sub
VB.NET事件通道相关共用方法就为大家介绍到这里。
【编辑推荐】
新闻名称:VB.NET事件通道使用技巧须知
网站地址:http://www.shufengxianlan.com/qtweb/news5/509005.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联