将rtf文本从另一个RTF文本框中插入RTF文本框中 [英] Insert a rtf text into rich textbox from another rich text box

查看:132
本文介绍了将rtf文本从另一个RTF文本框中插入RTF文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


简而言之:
我需要从RTF字符串中提取文本,向其中添加更多文本,然后再将其转换回RTF.


详细说明:
我有一个带有富文本框的表单(例如mainRichTextBox).在这个主要的RTF文本框中,我通过另一种形式(例如"InsertTextRtf"形式)输入了一些文本.

我可以通过具有一个富文本框的"InsertTextRtf"表单插入文本.

现在的情况是:

mainRichTextBox已输入以下行:


第1行:大家好.

第2行:您能给我解决方法吗?

第3行:谢谢.

现在,对于mainRichTextBox,将有一些RTF代码.

现在,我想在第1行和第2行之间插入一些文本.但是,该行将使用格式从"InsertTextRtf"插入.

我想将此文本插入到"mainRichTextBox"中,并同时保留InsertTextRtf和mainRichTextBox的格式.


如果我们同时使用RTF属性使用这两个RTF,则我们不能简单地将它们插入另一个RTF.

如何将RTF文本(RichTextBox)插入另一个RTF文本(RichTextBox).

谢谢,
约瑟夫.

Hello


In short:
I have the need to extract the text from an RTF string, add some more text to it, and then convert it back into RTF.


In Detail:
I have one form with rich text box (say mainRichTextBox). In this main rich text box i have some text entered via another form (Say "InsertTextRtf" form).

I am just able to insert a text through "InsertTextRtf" form which has a one rich text box.

Now the case is :

mainRichTextBox have a following lines already entered:


Line 1: Hi hello all.

Line 2: Can you give me the solution.

Line 3: Thanks.

Now for mainRichTextBox there will be some RTF code.

Now I want to insert some text between Line 1 & Line 2. But this line will be inserted from "InsertTextRtf" with formatting.

I want to insert this text into "mainRichTextBox" with persisting formatting of both InsertTextRtf & mainRichTextBox.


If we take RTF of both using RTF property we can not simply insert into one another RTF''s.

How can i insert a RTF text (RichTextBox) into another RTF text (RichTextBox).

Thanks,
Joseph.

推荐答案

将其设置为Web浏览器的主页,请注意,其URL与您的完整类名相似. system.windows.forms.richtextbox [
Set this as your homepage for your webbrowser, please note that it''s URL is similar to your full classname; system.windows.forms.richtextbox[^]


  1. 您可以使用文本 [ SelectionStart [ ^ ]和 SelectionLength [ SelectionColor [ ^ ]和 SelectionFont [

  1. You can use the Text[^] property to retrieve the text without any markup.
  2. You can use SelectionStart[^] and SelectionLength[^] to select a piece of text, say the one without markup that you inserted.
  3. You can then use SelectionColor[^] and SelectionFont[^] to apply a specific formatting to that selected piece of text. There''s more ways of manipulating the RichTextBox, as there are also properties for alignment and indentation. Browse a bit on your new homepage, you''ll find some very helpfull things.


我个人最喜欢的是
SelectionProtected [


My personal favorite would be SelectionProtected[^]

You can use this property to prevent the user from modifying sections of text within the control



噢,作为另外的建议,将轻量级的数据保留在内存中会比较方便.怎么样,System.Generic.List< mymessage>与MyMessage看起来有点类似下面的内容?



Aw, as an additional suggestion, it would be handier to keep a lightweight version of the data in Memory. How a about a System.Generic.List<mymessage>, with MyMessage looking somewhat similar to like below?

public class MyMessage
{
    Public String EmailSender { get; set; }
    Public String MessageContent { get; set; }
    Public DateTime FellIntoOurInboxOn { get; set; }
}


现在,您可以将数据存储在内存中的某个位置,并且您可以随意操作两个视图,不仅可以按内容,还可以按格式进行操作.

最后一个小技巧;
DetectURLS [


Now, you would have the data somewhere in memory, and you have two views that you can manipulate at will, not only by content, but also in formatting.

A last quick tip; DetectURLS[^] is what you''d need if you want to have urls'' in your RichTextBox - adding additional clickable functionality, so the user can invoke an action inlined with what he reads. The hyperlink click could be handled inside your application, if I recall correctly, could launch another application, or fetch a website.


这篇关于将rtf文本从另一个RTF文本框中插入RTF文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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