RichTextBox在文本中间添加一些文本 [英] RichTextBox add some text in the middle of the text

查看:265
本文介绍了RichTextBox在文本中间添加一些文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RichTextBox,我想在textmiddle中使用add some text. 例如,我得到了这段文字:

I have a RichTextBox and I want to add some text in the middle of the text. For example I got this text:

"FirstText SecondText"

"FirstText SecondText"

我想在"FirstText" and the "SecondText".之间添加一些文本 我试图split the text to 2 strings并在第一个文本中添加我的多余文本,然后在第二个字符串中添加他.它起作用了,但是却破坏了我的richTextBox1.SelectionColor (I got color...). 那么如何在不剪切richTextBox1.Text的情况下添加文本,或者如何保存所有颜色数据?

I want to add some text between the "FirstText" and the "SecondText". I have tried to split the text to 2 strings and add to the first my extra text then add him the second string. It worked but it is destroy my richTextBox1.SelectionColor (I got color...). So how can I add text without cutting my richTextBox1.Text or How can I save all the color data?

推荐答案

您是否熟悉开始位置和结束位置?您可以简单地执行以下操作

Are you familiar with the starting position and ending positions ? you could simply do something like this

richTextBox1.SelectionStart = index;
richTextBox1.SelectionLength = length;//you need to assign an integer where to start
richTextBox1.SelectedText =  "Good"; 

它将用"Good"一词替换文本中您已为其指定长度的任何位置

it will replace whatever position in text where you have assigned length with the word "Good"

这篇关于RichTextBox在文本中间添加一些文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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