RichTextBox在文本中间添加一些文本

编程入门 行业动态 更新时间:2024-10-27 23:28:38
本文介绍了RichTextBox在文本中间添加一些文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个RichTextBox,我想在text的middle中使用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在文本中间添加一些文本

本文发布于:2023-11-04 21:47:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559099.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   RichTextBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!