为什么 Richtextbox 不能正确显示此表? [英] Why isn't the richtextbox displaying this table properly?

查看:65
本文介绍了为什么 Richtextbox 不能正确显示此表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然,Microsoft 提供的 RichTextBox 并不完全支持 RTF 规范.出于某种原因,它不允许多行行,而是破坏格式.

例如,这里是生成表格的 RTF 代码:

\par\trowd\trgaph108\trleft36\trqc\trrh280\trpaddl108\trpaddr108\trpaddfl3\trpaddfr3\cellx2000\cellx4000\cellx6000\cellx6500\cellx8500\cellx9000\cellx11000\pard\intbl 重播前的时间长度\cell\cell Flate Fee Percentage\cell\cell Broker and Application Fees\cell\cell 案件的总留置权\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 月份 \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 月份 \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 月份 \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 月份 \cell 300% \cell\cell 310 \cell\cell\{#TOTALLIEN37#\} \cell

如果同时使用 word 和写字板,这可以正常工作.文本太长的顶行分成多行,然而,在 Richtext 框中,它做了一些古怪的事情.

写字板看起来像这样:写字板 RTF 表 http://img231.imageshack.us/img231/2720/wordpadrtf.jpg>

富文本框看起来像这样:富文本框表格 http://img262.imageshack.us/img262/9756/richtextboxrtf.jpg

如何让富文本框正常工作?

解决方案

我找到了解决方案.显然,每个系统上都有不止一个 RichEdit 库,并且默认为旧版本(我认为是 4.0).5.0 修复了大部分 RTF 解释的问题.要获得使用它的 RichtextBox,您必须使 RichTextBox 无效,并重载 CreateParams 属性.

我是这样做的:

public partial class FullRichtextBox : RichTextBox {公共 FullRichtextBox() :base() {初始化组件();}[DllImport("kernel32.dll", CharSet = CharSet.Auto)]静态外部 IntPtr LoadLibrary(string lpFileName);受保护的覆盖 CreateParams CreateParams {得到 {CreateParams param = base.CreateParams;如果(LoadLibrary(msftedit.dll")!= IntPtr.Zero){param.ClassName = "RICHEDIT50W";}返回参数;}}}

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?

解决方案

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:

public partial class FullRichtextBox : RichTextBox {
    public FullRichtextBox() :base() {
        InitializeComponent();
    }
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr LoadLibrary(string lpFileName);

    protected override CreateParams CreateParams {
        get {
            CreateParams param = base.CreateParams;
            if (LoadLibrary("msftedit.dll") != IntPtr.Zero) {
                param.ClassName = "RICHEDIT50W";
            }
            return param;
        }
    }
}

这篇关于为什么 Richtextbox 不能正确显示此表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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