加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

注册事件,使其生效,订阅事件(VB)

发布时间:2020-12-16 22:31:21 所属栏目:大数据 来源:网络整理
导读:VB.NET中的List用法 Public list As New List(Of String) Private Delegate Sub ButtonStartEnableCallback(ByVal enable As Boolean) Private Delegate Sub ButtonStopEnableCallback(ByVal enable As Boolean) If Not list.Contains(string) Then list.Add

VB.NET中的List用法

Public list As New List(Of String)

Private Delegate Sub ButtonStartEnableCallback(ByVal enable As Boolean)
Private Delegate Sub ButtonStopEnableCallback(ByVal enable As Boolean)

If Not list.Contains(string) Then
list.Add(string)
Dim show As ShowTags = New ShowTags(AddressOf ListViewShow)
BeginInvoke(show,string)
End If

Public Delegate Sub ShowTags(ByVal tag As Tag)
Public Sub ListViewShow(ByVal tag As Tag)
Dim a As String = (ListView1.Items.Count + 1).ToString()
Dim item1 As ListViewItem = New ListViewItem(a)

item1.SubItems.Add(tag.Epc)
item1.SubItems .Add (tag.SerializedTid)
ListView1.Items.AddRange(New ListViewItem() {item1})

Me.Label2.Text = a

End Sub

// 防止非线程的访问该控件

Private Delegate Sub ButtonStartEnableCallback(ByVal enable As Boolean)
Private Delegate Sub ButtonStopEnableCallback(ByVal enable As Boolean)


Private Sub StartEnable(ByVal enable As Boolean)

If (Button3.InvokeRequired) Then

Dim method As New ButtonStartEnableCallback(AddressOf Me.StartEnable)
Me.Invoke(method,New Object() {enable})

Else

Button3.Enabled = enable
End If

End Sub

Private Sub StopEnable(ByVal enable As Boolean)

If (Me.Button4.InvokeRequired) Then

Dim method As New ButtonStopEnableCallback(AddressOf Me.StopEnable)
Me.Invoke(method,New Object() {enable})

Else

Me.Button4.Enabled = enable
End If

End Sub

2. 事件的声明,定义和订阅

Public Class Form1

Public Sub New()
InitializeComponent()
' have to instantiate the controller
' it wraps the SpeedwayReader class

AddHandler _speedwayReader.Connected,AddressOf _speedwayReader_Connected


End Sub

Public Event Connected As EventHandler(Of ConnectionChangedEventArgs)

Public Sub _speedwayReader_Connected(ByVal sender As Object,ByVal e As ConnectionChangedEventArgs)
RaiseEvent Connected(sender,e)
Button2.Enabled = True
Button3.Enabled = True
Button1.Enabled = False

' MsgBox(e.State.ToString)

End Sub

End Class

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读