2 个丰富的编辑控件,相同的文本
我放置了 2 个丰富的编辑控件,它们应该显示相同的文本。因此,当我在其中一个编辑文本时,另一个应该反映更改。 问题是 - 我不想将此代码放在“文本更改”事件中:
control1.rftText = control2.rtfText
因为每次编辑文本时它都会创建一个新的字符串实例。
有没有办法将字符串的相同实例发送到两个控件,或者是否有其他解决方案?
I've put 2 rich edit controls, which should display the same text. So, when I edit the text in one of them, the other should reflect the changes.
The problem is - I don't want to put this code in Text Changed event:
control1.rftText = control2.rtfText
because it will create a new instance of the string each time the text is edited.
Is there any way to send the same instance of the string to the both of the controls or are there any other solutions to the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
control1.rftText
是一个不可变的字符串,因此如果您想修改它,则必须创建一个新字符串。使用此
control1.rftText = "my new string"
将简单地创建一个新字符串并将其指定到rftText
字段,如您所说。如果您真的很认真地想优化这种赋值,您可以创建自己的派生丰富编辑类的实现,其中它将使用某种StringBuilder
逻辑,或者您可以在内部表示文本作为 char[] 数组并对其进行修改,但它们可能会成为一个真正的挑战,因此请明智地做出决定。control1.rftText
is an immutable string so if you want to modify it, you'll have to create a new string.Using this
control1.rftText = "my new string"
will simply create a new string and appoint it torftText
field as you said. If you are really serious about optimizing this sort of value assignments, you can create your own implementation of a derived rich edit class where it will use some sort of aStringBuilder
logic, or you may internally represent the text as a char[] array and modify that, but they may turn out to be a real challenge, so decide wisely.