0

当 var 更改时,我想在 VB.NET 中执行 If。例子:

If var testvar change do this if Then
            Me.RichTextBox1.Text = "Hello World"
        End If
4

1 回答 1

1

您要做的是创建一个类来包装您的变量,并在变量更改时引发一个事件。例如,您的侦听器(表单)然后订阅事件并响应它。

Imports System
Class MyClass
  Private x As Integer
  Public Sub SetX(ByVal i As Integer)
    x = i
  End Sub

  Public Function GetX() As Integer
    Return x
  End Function

  Public Event Changed(ByVal sender As Object, ByVal e As EventArgs)

  Protected Overridable Sub OnChanged(ByVal e As EventArgs)
    RaiseEvent Changed(Me, e)
  End Sub
End Class

有关更多信息,请参见此处。

http://www.codeproject.com/Articles/5041/Step-by-Step-Event-handling-in-VB-NET http://msdn.microsoft.com/en-us/library/ms172877(v=vs .80).aspx

于 2013-01-27T10:53:49.120 回答