vb.net 如何在 Richt 文本框的文本字符串中添加 rtf 格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13265762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:03:13  来源:igfitidea点击:

How to add a rtf formatting in the text string for a Richt Text Box?

c#.netvb.netrichtextboxrtf

提问by gingo

In a .NET project I have a long plain text build as concatenation of several strings

在 .NET 项目中,我有一个很长的纯文本构建作为几个字符串的串联

StringLongText = text1 + text2 + ... + textN

each string "textX" is the result of an evaluation. At the end of a started process, I show the result in a RichTextBox doing simply:

每个字符串“textX”都是评估的结果。在启动过程结束时,我在 RichTextBox 中显示结果,只需执行以下操作:

rtfTxt.Text = StringLongText

All works fine, but I am not able to add any text formatting in the previous text1, text2, textN blocks.

一切正常,但我无法在之前的 text1、text2、textN 块中添加任何文本格式。

For example I would like to write some words in bold or italic including the formatting directly in the strings before concatenating them.

例如,在连接字符串之前,我想用粗体或斜体写一些单词,包括直接在字符串中的格式。

Doing

正在做

text1 = "This is some {\b bold} text"
rtfTxt.Text = text1

did not work.

不工作。

Any suggestion? Thank you for your help.

有什么建议吗?感谢您的帮助。

回答by Danilo Vulovi?

rtfTxt.Rtf = @"{\rtf1\ansi This is some \b bold\b0 text.}";

回答by Tilak

Just write required content with formatting to RTF File. Load RTF file in richtextbox. Verify. Read RTF content into the textbox. Put textbox content to RTF as:

只需将所需的内容格式化为 RTF 文件即可。在富文本框中加载 RTF 文件。核实。将 RTF 内容读入文本框。将文本框内容放到 RTF 中:

Richtext.rtf = textbox1.text; // (which is textual content)