在文本更改事件中更改TextBox文本属性 [英] Change TextBox text property in text changed event

查看:116
本文介绍了在文本更改事件中更改TextBox文本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本更改事件中修改文本框的文本属性.但是如何再次执行文本更改事件而不引发?

I want to modify text property of text box in text changed event.But how to do again text changed event not to raise?

推荐答案

您的文本更改将总是引发一个新的TextChanged事件-防止其发生作用的唯一方法是取消挂接"事件处理程序,更改文本,然后重新挂接该处理程序-这是一种讨厌的处理方式.相反,我将设置一个类级别的布尔值,在事件处理程序的顶部进行测试:如果为true,则忽略该处理程序,并将其设置为false.如果为假,则在更改Text属性之前,与处理程序继续并将其设置为true.
Your text change will always raise a new TextChanged event - the only way to prevent it being actioned is to "unhook" the event handler, change the text and then re-hook the handler - which is a nasty way to do things. Instead, I would set up a class level bool which you test at the top of the event handler: if it is true, ignore the handler and just set it false. If it is false, contiunue with the handler, and set it true just before you change the Text property.


这篇关于在文本更改事件中更改TextBox文本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆