将2个RichTextbox中的格式丰富的文本附加到C#中的另一个RichTextBox中 [英] Append rich formatted text from 2 RichTextboxes into another RichTextBox in C#

查看:98
本文介绍了将2个RichTextbox中的格式丰富的文本附加到C#中的另一个RichTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个RichTextBoxes:richTextBox1,richTextBox2和richTextBox3。

I have 3 RichTextBoxes: richTextBox1, richTextBox2 and richTextBox3.

我运行应用程序,并在文本框1和2中输入文本。

I run the app and enter text into textbox 1 and 2.

因此,richTextBox1的文本为 Test,richTextBox2的文本为 ing。

So the text for richTextBox1 is "Test" and for richTextBox2 is "ing".

我现在想将该文本附加在一起并放入放入另一个richTextBox中(保留任何粗体,下划线等格式)

I now want to append that text together and put it into another richTextBox (preserving any formatting like bold, underlining, etc...)

所以我尝试了以下代码:

So I try the following code:

richTextBox3.Rtf = richTextBox1.Rtf + richTextBox2.Rtf;

这不会引起任何错误,但我只能从richTextBox1中获取文本。所以我得到测试。

This doesn't cause any error but I only get the text from richTextBox1. So I get "Test".

那么我如何在保留格式的同时复制2个RichTextBoxes的内容?

So how do I copy the contents of the 2 RichTextBoxes while keeping the format?

Ta

推荐答案

您将要执行以下操作:

richTextBox3.Rtf = richTextBox1.Rtf
richTextBox3.Select(richTextBox3.TextLength, 0);
richTextBox3.SelectedRtf = richTextBox2.Rtf;

这应该可以解决问题。

这篇关于将2个RichTextbox中的格式丰富的文本附加到C#中的另一个RichTextBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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