我有一个事件处理程序可以很好地处理它的事件。但是,我不想直接调用处理程序,或者更具体地说,让我的程序员同事能够直接调用它,因为我只想在设置激光电流时更新 nudCurrent.Value。
Public Class TestClass
Dim WithEvents myCurrentSource As New CurrentSourceClass
Private Sub TestScript()
'among other things, sets current to 85
myCurrentSource.SetCurrent(85)
End Sub
Private Sub handleLaserCurrentSet() Handles myCurrentSource.LaserCurrentSet
Me.nudCurrent.Value = myCurrentSource.GetCurrent()
End Sub
End Class
Public Class CurrentSourceClass
Public Event LaserCurrentSet()
Private currentSet As Double = Double.NaN
Public Sub SetCurrent(ByVal dCurrentAmps As Double)
' set the current on the current source here
Me.currentSet = dCurrentAmps
' then raise the event
RaiseEvent LaserCurrentSet()
End Sub
Public Function GetCurrent() As Double
Return Me.currentSet
End Function
End Class
我想不出一种方法来限制对其范围内的事件处理程序例程的访问,所以我正在寻找一种替代方法。最佳做法是什么?
*我知道我可以me.nudCurrent.Value = 85
在设置电流后放置,但我喜欢事件驱动的 UI 更新的简洁性。我可以把我的蛋糕也吃掉吗?