可以在声明对象变量时使用“WithEvents”将它指向当前选定的对象。该变量即可响应当前选定对象的触发事件。该方法允许在不同的对象间共享相同的代码。

    可以比较一下和set的细微差别,2者的事件有所差异。

     还是拿原来那个 趋势图一拉游标,所有点就变时间的例子,你可以看看区别。

     我们把所有的trend 声明成 withEvents的 一个TNDX 对象

     当你选择一个趋势图的时候  我们set它为 tndX

    tndx也是一个对象,事件就是DropCursor

Option Explicit

Dim WithEvents tndX As PBSymLib.Trend
 

Private Sub Display_SelectionChange()

Dim smbX As PBObjLib.Symbol

For Each smbX In Application.ActiveDisplay.SelectedSymbols

    If smbX.Type = pbSymbolTrend Then

        Set tndX = smbX

    End If

Next smbX

End Sub
 

Private Sub tndX_DropCursor(bCancel As Boolean, ByVal nCursor As Integer, ByVal NewTime As String)

Dim smbY As PBObjLib.Symbol

For Each smbY In thisdisplay.Symbols

    If smbY.Type = pbSymbolValue Then

        smbY.SetTimeRange “”, NewTime

    End If

Next smbY

End Sub


相关文章:

  • 2022-12-23
  • 2021-12-21
  • 2022-03-04
  • 2022-03-03
  • 2021-12-14
  • 2021-09-24
  • 2021-12-09
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-12-03
  • 2021-08-21
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案