c# – 如何将rtf字符串提供给richtextbox控件
发布时间:2020-12-15 18:10:10 所属栏目:百科 来源:网络整理
导读:我有一串richtext字符/标记,我想在代码中提供给richtextbox. string rt = @" {rtf1ansiansicpg1252deff0deflang1033{fonttbl{f0fswissfcharset0 Arial;}{f1fnilfprq2fcharset0 Biondi;}}"+@"{colortbl ;red255green0blue0;}"+@"{*generat
我有一串richtext字符/标记,我想在代码中提供给richtextbox.
string rt = @" {rtf1ansiansicpg1252deff0deflang1033{fonttbl{f0fswissfcharset0 Arial;}{f1fnilfprq2fcharset0 Biondi;}}"+ @"{colortbl ;red255green0blue0;}"+ @"{*generator Msftedit 5.41.15.1507;}viewkind4uc1pardf0fs20par"+ @"cf1f1 hellocf0f0 ul worldpar}"; 我试过这个: System.IO.MemoryStream strm = new System.IO.MemoryStream(); byte[] b = Encoding.ASCII.GetBytes(rt); strm.BeginRead(b,b.Length,null,null); richTextBox1.LoadFile(strm,RichTextBoxStreamType.RichText); 它不起作用. 任何人都可以给我一些sugestions. 顺便说一下,富文本来自于从wordpad保存,用记事本打开文件,并使用in来构建我的字符串 解决方法
富文本框具有名为Rtf的属性.将该属性设置为您的字符串值.此外,您的字符串还有一个额外的空格作为第一个字符.在看到你的Hello World之前我不得不删除它.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |