Rtf文件有问题 [英] Rtf file trouble

查看:104
本文介绍了Rtf文件有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rtf文件有问题。在许多情况下,当我尝试将Rtf格式的文本分配给我的扩展富文本控件时,我可以看到显示的所有格式化字符。这是代码的一个片段。

 case'K':// subscriptions 
result = FillTables.GetOneMemo(" subscriptions" ,numeric_id);
休息;
case'U':// urls
result = FillTables.GetOneMemo(" urls",numeric_id);
休息;
}
尝试
{
richTextBox_pg3.Rtf = result; < ==例外。
}
catch
{
richTextBox_pg3.Text = result;
}

我想要注意的是我大约15年前首次设计这个项目。可能是MS改变了控件的格式规则吗?在这里你可以看到我在尝试为控件分配格式化为Rtf的文本(我从SQL Server
得到它并且那些记录是15年)时得到一个例外,但我最终将它指定为一个普通的所有格式字符都可见的文字。


谢谢, - MyCatAlex


解决方案

您好MyCatAlex,


对于迟到的回复感到抱歉。


>> richTextBox_pg3.Rtf = result;  < ==例外。


这里的主要问题是属性:
RichTextBox.Rtf < /强>


以下是规范:获取或设置RichTextBox控件的文本, 包括所有富文本格式(RTF) )代码


这意味着您无法直接将文本值设置为"Rtf"。属性。


检查rtf属性时,调试值类似于

" {\\\\\ \\\\\pgpg1252 \\deff0 \\deflang1033 {\\fonttbl {\\f0 \\fnil\\fcharset0 Microsoft Sans Serif;}} \ r \\\
\\viewkind4\\uc1\\pard\\f0\\fs17\\par\r\\\
} \r\\\
"

因此,如果要设置RichTextBox.Rtf值,则需要
设置整个RTF代码到RichTextBox。


按照以下链接将帮助您如何使用"Rtf"财产:


C# - 通过解析RTF格式(RTF)格式化RichTextBox中的文本


在RichTextBox中重置RTF?


问候,


斯坦利


I have a problem with my Rtf file. In many cases when I try to assign Rtf formatted text to my Extended Rich Text Controls I can see all formatting characters on display. This is a fragment of the code.

                case 'K':  // subscriptions
                    result = FillTables.GetOneMemo("subscriptions", numeric_id);
                    break;
                case 'U':  // urls
                    result = FillTables.GetOneMemo("urls", numeric_id);
                    break;
            }
            try
            {
                richTextBox_pg3.Rtf = result;  <== exception here.
            }
            catch
            {
                richTextBox_pg3.Text = result;
            }

I want to note that I first designed this project about 15 years ago. Could it be that MS has changed the formatting rules for the control? Here you can see that I get an exception while trying to assign the text formatted for Rtf (I get it from SQL Server and those records are 15 years old) to the control but I end up to assigning it as a plain text with all formatting characters visible.

Thanks,- MyCatAlex

解决方案

Hi MyCatAlex,

Sorry for the late reply.

>>richTextBox_pg3.Rtf = result;  <== exception here.

The main issue here is the property: RichTextBox.Rtf.

Here is the specification: Gets or sets the text of the RichTextBox control,including all rich text format (RTF) codes.

That means you cannot directly set the text value to "Rtf" property.

When you check the rtf property while debugging the value is like

"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Microsoft Sans Serif;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs17\\par\r\n}\r\n"

So if you want to set the RichTextBox.Rtf value, you will need to set the whole RTF code to the RichTextBox.

Follow the below links will helps you how to work with "Rtf" property:

C# - Formatting Text in a RichTextBox by Parsing the Rich Text Format (RTF)

Reset RTF in RichTextBox?

Regards,

Stanly


这篇关于Rtf文件有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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