本文介绍了绕过textchange事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当txtsearch.text = String.Empty行执行时,如何绕过TextChange事件.这是两次执行消息框,请建议该怎么做

How can I bypass TextChange event when txtsearch.text=String.Empty line executes. This is executting messagebox two time, please suggest what to do

Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If rdoName.Checked = True Then
            some codes here
        Else
            MessageBox.Show("Select any Search Criteria First,MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtSearch.Text = String.Empty
        End If
End Sub

推荐答案


Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If rdoName.Checked = True Then
            some codes here
        Else
            MessageBox.Show("Select any Search Criteria First",MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            RemoveHandler txtSearch.TextChanged,AddressOf txtSearch_TextChanged
            txtSearch.Text = String.Empty
            AddHandler txtSearch.TextChanged,AddressOf txtSearch_TextChanged
        End If
End Sub







or

Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
        If txtSearch.Text = String.Empty Then Exit Sub
        If rdoName.Checked = True Then
            some codes here
        Else
            MessageBox.Show("Select any Search Criteria First",MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtSearch.Text = String.Empty
        End If
End Sub


这篇关于绕过textchange事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 09:33