兩種方式:
暫時移除處理程序,以防止事件再次射擊:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
MsgBox("txt was changed")
RemoveHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
TextBox1.Clear()
AddHandler TextBox1.TextChanged, AddressOf TextBox1_TextChanged
End Sub
或
創建一個字段,檢查如果事件是從自身起源:
Dim textBoxAlreadyChanging As boolean = False
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If Not textBoxAlreadyChanging Then
MsgBox("txt was changed")
textBoxAlreadyChanging = True
TextBox1.Clear()
textBoxAlreadyChanging = False
End If
End Sub
清除觸發器再次呼叫您的事件處理程序 – Steve
是的我知道臨時但我想清理文本框並只顯示一次msgbox,我可以這樣做嗎? –