为什么 Richtextbox 无法正确显示该表格?
显然,微软提供的RichTextBox并不完全支持RTF规范。由于某种原因,它不允许多行行,并且会破坏格式。
例如,下面是生成表格的 RTF 代码:
\par
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl Length of Time until Replayment\cell\cell Flate Fee Percentage\cell\cell Broker and Application Fees\cell\cell Total lien on case\cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 0-6 \cell Months \cell 40% \cell\cell 310 \cell\cell\{#TOTALLIEN0-6#\}\cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 7-12 \cell Months \cell 60% \cell\cell 310 \cell\cell\{#TOTALLIEN7-12#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 13-18 \cell Months \cell 100% \cell\cell 310 \cell\cell\{#TOTALLIEN13-18#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 19-24 \cell Months \cell 150% \cell\cell 310 \cell\cell\{#TOTALLIEN19-24#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 25-36 \cell Months \cell 200% \cell\cell 310 \cell\cell\{#TOTALLIEN25-36#\} \cell
\row\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 37+ \cell Months \cell 300% \cell\cell 310 \cell\cell\{#TOTALLIEN37#\} \cell
如果 word 和 wordpad 都可以正常工作。文本太长的顶行分成多行,但是,在 Richtext 框中,它做了一些古怪的事情。
写字板看起来像这样: 写字板 RTF 表 http://img231.imageshack.us/img231/2720/wordpadrtf.jpg
Richtext 框如下所示: richtextbox 表 http://img262.imageshack.us/img262/9756/richtextboxrtf.jpg
我怎样才能使richtextbox正常工作?
Apparently, the RichTextBox provided by Microsoft doesn't fully support the RTF specs. For some reason, it won't permit multi-lined rows, and destroys formatting instead.
Forexample, here is the RTF code to generate a table:
\par
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl Length of Time until Replayment\cell\cell Flate Fee Percentage\cell\cell Broker and Application Fees\cell\cell Total lien on case\cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 0-6 \cell Months \cell 40% \cell\cell 310 \cell\cell\{#TOTALLIEN0-6#\}\cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 7-12 \cell Months \cell 60% \cell\cell 310 \cell\cell\{#TOTALLIEN7-12#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 13-18 \cell Months \cell 100% \cell\cell 310 \cell\cell\{#TOTALLIEN13-18#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 19-24 \cell Months \cell 150% \cell\cell 310 \cell\cell\{#TOTALLIEN19-24#\} \cell\row
\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 25-36 \cell Months \cell 200% \cell\cell 310 \cell\cell\{#TOTALLIEN25-36#\} \cell
\row\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3
\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000
\pard\intbl 37+ \cell Months \cell 300% \cell\cell 310 \cell\cell\{#TOTALLIEN37#\} \cell
This works fine if both word and wordpad. The top row where the text is too long breaks into multipule lines, however, in the Richtext box it does something wacky.
Wordpad looks like this:
wordpad RTF table http://img231.imageshack.us/img231/2720/wordpadrtf.jpg
And the Richtext box looks like this:
richtextbox table http://img262.imageshack.us/img262/9756/richtextboxrtf.jpg
How can I make the richtextbox work properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。显然,每个系统上都有多个 RichEdit 库,并且默认为旧版本(我认为是 4.0)。 5.0 修复了 RTF 解释的大部分问题。要获取使用它的 RichtextBox,您必须惰性 RichTextBox,并重载 CreateParams 属性。
我是这样做的:
I found the solution. Evidently, there are more than one RichEdit library on every system, and the default to an older version (4.0 I think). 5.0 has fixed most of the problems with the RTF interpretation. To get a RichtextBox that uses it, you must inert RichTextBox, and overload the CreateParams property.
Here is how I did it:
我最近遇到了一个类似的问题,虽然接受的答案有效,但我还在这个堆栈溢出问答中找到了一个有趣的解决方案: https:// stackoverflow.com/a/48391710
这意味着我可以继续使用 .NET 4.5.2 和最新的 RichTextBox,而无需创建自定义类等。不过,我可能应该在某些时候更新到 .NET 4.7+观点。
I recently came across a similar problem and while the accepted answer worked, I also found an interesting solution on this stack overflow q&a: https://stackoverflow.com/a/48391710
This meant that I could continue to use .NET 4.5.2 with the latest RichTextBox without creating a custom class, etc. Although, I should probably just update to .NET 4.7+ at some point.