0
我有一个事件处理程序,它处理它的事件就好了。但是,我不想直接调用处理函数,或者更具体地说,让我的同伴程序员能够直接调用它,因为我只想在设置激光电流时更新nudCurrent.Value。 VB.net限制访问范围内的事件处理程序,或替代
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更新的整洁。我可以吃我的蛋糕,也可以吃吗?
谢谢。这是一个很好的选择,似乎是我唯一的选择。 – djv