如何将rtf字符串提供给richtextbox控件

我有一串richtext字符/标记,我想在代码中提供给richtextbox。

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); 

它不起作用。

任何人都可以给我几个sugestions。

BTW富文本来自于从wordpad保存,用记事本打开文件,并使用in来构建我的字符串

Rich textbox有一个名为Rtf的属性。 将该属性设置为您的字符串值。 此外,您的字符串还有一个额外的空格作为第一个字符。 在看到Hello World之前,我不得不删除它。

扩展gbogumil的答案:

 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}"; this.richTextBox1.Rtf = rt;