VB.NET能自己定义一个事件,比如一个变量等于一个特定值时引发一个事件的触发吗?
比如定义一个变量i
当i=1时触发一个事件
自己定义一个方法把i封装起来,要改变i需要通过这个方法修改
比如
public sub modifyI(byval i1 as integer)
i = i1
'触发事件
end sub
或者
用定时器的方式
Public class Form1
Public y_change, y_0 As String
private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
y_change = Nothing : y_0 = Nothing
Timer1.Interval = 100
Timer1.Enabled = True
end Sub
private Sub TextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
y_change = TextBox1.Text
end Sub
private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
If y_change <> y_0 Then
MsgBox("变量值改变") '变量值改变时触发事件
y_0 = y_change
End If
Timer1.Enabled = True
End Sub
End Class
可以,把那个变量设置为属性
Private i As Integer
Public Property I As Integer
Get
Return i
End Get
Set
i = Value
If i = 特定值 Then
RaiseEvent 某某事件
End If
End Set
End Property