如何将rtf字符串输入RichTextBox控件 [英] how do I feed an rtf string to a richtextbox control
本文介绍了如何将rtf字符串输入RichTextBox控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一串丰富的文本字符/令牌,我想用代码将它们馈送到一个丰富的文本框。
I have a string of richtext characters/tokens that I would like to feed to a richtextbox in code.
string rt = @" {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fnil\fprq2\fcharset0 Biondi;}}"+
@"{\colortbl ;\red255\green0\blue0;}"+
@"{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20\par"+
@"\cf1\f1 hello\cf0\f0 \ul world\par}";
我已经尝试过:
System.IO.MemoryStream strm = new System.IO.MemoryStream();
byte[] b = Encoding.ASCII.GetBytes(rt);
strm.BeginRead(b, 0, b.Length, null, null);
richTextBox1.LoadFile(strm, RichTextBoxStreamType.RichText);
它不起作用。
谁能给我一些建议。
BTW富文本来自于从写字板中保存,打开
BTW the rich text comes from saving from wordpad, opening the file with notepad and using the text with in to build my string
推荐答案
富文本框具有一个名为Rtf的属性。将该属性设置为您的字符串值。另外,您的字符串的第一个字符还有多余的空格。在看到您的Hello World之前,我不得不将其删除。
Rich textbox has a property named Rtf. Set that property to your string value. Also, your string has an extra space as the first character. I had to remove that before I saw your Hello World.
这篇关于如何将rtf字符串输入RichTextBox控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文