1

我想用 TextChange 事件更改文本框的文本,但 TextChanged evernt 不断触发。

我尝试 RemoveHandler 但它对我不起作用。但是,当我在 _TextChanged Sub 之外使用它时,它可以工作。

Private Sub txtLegalNameLast_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLegalNameLast.TextChanged
    RemoveHandler txtLegalNameLast.TextChanged, AddressOf txtLegalNameLast_TextChanged
    txtLegalNameLast.Text = "Mr. " + txtLegalNameLast.Text 
    AddHandler txtLegalNameLast.TextChanged, AddressOf txtLegalNameLast_TextChanged    

End Sub

编辑:以上对我有用。我应该测试过它。但是这个非常相似的代码没有。我正在对 Sub 之外的 Functions 中的文本框进行更改。这对我不起作用。

Private Sub txtLegalNameLast_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtLegalNameLast.TextChanged

        RemoveHandler txtLegalNameLast.TextChanged, AddressOf txtLegalNameLast_TextChanged

        txtLegalNameLast.Text = gsCapitalizeTextbox(txtLegalNameLast.Text) 'StrConv(txtLegalNameLast.Text, VbStrConv.ProperCase)
        txtLegalNameLast.Text = gsValidateName(txtLegalNameLast.Text)

        AddHandler txtLegalNameLast.TextChanged, AddressOf txtLegalNameLast_TextChanged

End Sub
4

0 回答 0