如何将不同文本大小的字符串从一个 RichTextBox 发送到另一个? [英] How do I send varying text sized strings from one RichTextBox to another?

查看:34
本文介绍了如何将不同文本大小的字符串从一个 RichTextBox 发送到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码含有化合物,下标的字体很小.我目前有此代码,可通过单击按钮将其从一个 RichTextBox 传输到另一个.

I have code that has chemical compounds that have small font for the subscript. I currently have this code that transfers it from one RichTextBox to another one on a Button click.

myRichTextBox.Text += otherRichTextBox.Text

otherRichTextBox 中,我有不同字体大小的化合物,但是当我这样做时,我最终在 myRichTextBox 中得到一个字符串,它不会保持不同的字体大小和将它们全部设置为框的主要属性字体和大小.

In otherRichTextBox I have the compound with varying font sizes however when I do this I end up with a string in myRichTextBox that doesn't keep the varying font sizes and sets them all to the boxes main properties font and size.

推荐答案

来自 文档:

Text 属性不返回有关应用于 RichTextBox 内容的格式的任何信息.要获取富文本格式 (RTF) 代码,请使用 Rtf 属性."

"The Text property does not return any information about the formatting applied to the contents of the RichTextBox. To get the rich text formatting (RTF) codes, use the Rtf property."

所以要分配值,带格式,使用这个:

So to assign the value, with formatting, use this:

myRichTextBox.Rtf = otherRichTextBox.Rtf;

我已将 += 替换为 = 因为我不确定您是否打算附加该值,而不仅仅是替换它.如果您确实使用 +=,您可能会遇到问题,因为rtf"代码被一个接一个地附加.但是,试一试……您可能根本不会遇到任何问题.

I've replaced += with = because I'm not sure you meant to append the value, rather than just replace it. If you do use +=, you may run into issues due to the "rtf" codes being appended one after the other. However, give it a try... you may not run into any issues at all.

这篇关于如何将不同文本大小的字符串从一个 RichTextBox 发送到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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