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

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值