在RichTextBox控件破表(自动换行) [英] Broken tables in RichTextBox control (word wrap)

查看:316
本文介绍了在RichTextBox控件破表(自动换行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/1928853/why-isnt-the-richtextbox-displaying-this-table-properly">Why不正确地显示该表中的RichTextBox的?

我们有问题的Windows.Forms.RichTextBox控制在Visual Studio 2008

We are having problems with the Windows.Forms.RichTextBox control in Visual Studio 2008.

我们正试图以显示一个Windows窗体应用程序(.NET 3.5),提供为RTF文件由第三方文本。在此RTF文本文件中有表,其中包含跨多行文字。当用写字板或Word 2003中打开RTF文件正确显示。

We are trying to display text supplied as an RTF file by a 3rd party in a windows forms application (.NET 3.5). In this RTF text file there are tables, which contain text that spans multiple lines. The RTF file displays correctly when opened with either WordPad or Word 2003.

然而,当我们加载RTF文件到RichTextBox控制,或复制和;粘贴整个文本(包括表)到控制,该表显示不正确 - 细胞只有一行,无包装

However, when we load the RTF file into the RichTextBox control, or copy & paste the whole text (including the table) into the control, the table does not display correctly - the cells are only single line, without wrapping.

下面链接到的图像显示确切的问题:

Here are links to images showing the exact problem:

错误地显示在RichTextBox控件

我已经用Google搜索没有成功的解决方案和第三方.NET RTF控制。我发现问另一个论坛上这个确切的问题没有答案(其实这就是链接到图片来自),所以我希望堆栈溢出​​做更好的;-)

I have googled for solutions and 3rd party .net RTF controls without success. I have found this exact problem asked on another forum without an answer (in fact that's where the link to the images come from) so I'm hoping stack overflow does better ;-)

我的preferred的解决办法是使用code或第三方控制,可正确显示RTF格式。不过,我怀疑的问题是,RichTextBox控件只支持完整的RTF规范的一个子集,因此另一种办法是直接修改RTF除去未负载控制codeS或以其他方式解决RTF文件本身(其中案件的任何信息,以codeS所需要的控制,应删除或修改将是一个巨大的帮助)。

My preferred solution would be to use code or a 3rd party control that can correctly render the RTF. However, I suspect the problem is that the RichTextBox control only supports a subset of the full RTF spec, so another option would be to modify the RTF directly to remove the unsupported control codes or otherwise fix the RTF file itself (in which case any information as to what control codes need to be removed or modified would be a huge help).

推荐答案

从.NET的丰富的文本框是非常马车。

The Rich Text box from .NET is extremely buggy.

在RTF,表的定义方式实际上是从你可以期望,如果你是用HTML完全不同。

In RTF, the way a table is defined is actually quite different from what you could expect if you are used to HTML.

HTML:

<table>
<tr>
    <td>Mycell</td>
</tr>
</table>

在RTF,表是一系列与控制字定义行,单元格边框段落。有一个表的开始/结束没有组标记。

In RTF, a table is simply a series of paragraphs with control words defining rows, cells, borders. There is no group tag for the start/end of a table.

RTF:

\trowd\trgraph \cellx1000 Mycell \cell\row\pard\par

如果你想添加一个段落在细胞内,可以使用\杆和控制\ intbl(表)来指示该段是在表内。

If you want to add a paragraph inside a cell, you use \par and the control \intbl (in table) to indicate the paragraph is inside the table.

.NET RTB可以处理RTF控制字只有一个很小的子集,并且不支持用命令的绝大多数。通过对事物的外表,\ intbl是控制字不支持的长长名单的一部分,如果它实际上解析\杆在这一点上,显示是丢弃。

.NET RTB can handle only a very small subset of RTF control words and doesn't support the vast majority of available commands. By the looks of things, \intbl is part of the long long list of control words it doesn't support, and if it actually parses \par at that point, the display is trashed.

不幸的是,我没有为一个解决方案,但我希望上面的小说明帮助您的问题有所了解。

Unfortunately, I don't have a solution for that but I hope the small explanation above helps you make some sense of the problem.

不要过于相信我的RTF样品。它的工作原理,但它绝对是裸机。你可以下载从微软的网站的RTF规格: <一href="http://www.microsoft.com/downloadS/details.aspx?familyid=DD422B8D-FF06-4207-B476-6B5396A18A2B&displaylang=en"相对=nofollow> Word 2007中RTF规范的。

Don't put too much faith on my RTF sample. It works, but it's absolutely bare-bones. You can download the RTF specifications from Microsoft's website: Word 2007 RTF specs.

这篇关于在RichTextBox控件破表(自动换行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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