如何从RichTextBox删除附加的文本 [英] How to Remove Appended Text from RichTextBox

查看:91
本文介绍了如何从RichTextBox删除附加的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了appendText()函数将文本追加到RichTextBox中,现在如何清除RichTextBox的文本

在此先感谢.

I have used the appendText() function to append text to RichTextBox Now How do I clear the RichTextBox''s Text

Thanks in Advance.

推荐答案

使用 ^ ]


这是您不应该要做的事情:不为,并且不要将其分配给属性Text.不要尝试使用属性Rtf做类似的事情. (这仅适用于System.Windows.Forms.RichTextBox,不能用于WPF System.Windows.Controls.RichTextBox.)

这是您应该做的:使用正确的SelectionStartSelectionEnd选择所需的文本,然后将属性SelectedText分配给string.Empty.

另外,请注意:这些控件具有撤消功能;您可以使用它.

参见:
http://msdn.microsoft.com/en-us/library/system. windows.forms.richtextbox.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.controls.richtextbox.aspx [ ^ ].

始终标记要使用的UI库,不要让专家做双重工作!

—SA
Here is what you should not do: do not calculate new text for the instance of RichTextBox and do not assign it to the property Text. Do not try to do something like that with the property Rtf. (This is applicable to System.Windows.Forms.RichTextBox only, you cannot do it for WPF System.Windows.Controls.RichTextBox.)

Here is what you should do: select the text you need using the properly SelectionStart and SelectionEnd, then assign the property SelectedText to string.Empty.

Also, pay attention: these controls have Undo functionality; you can use it.

See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx[^].

Please, always tag UI library you want to use, don''t make experts doing double work!

—SA


这篇关于如何从RichTextBox删除附加的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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