我想用TextChange事件更改文本框的文本,但TextChanged永远不会触发。
我尝试使用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中的函数中对文本框进行更改。这不适合我。
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