使用较新的RichEdit版本?

dar*_*021 5 .net richedit richtextbox

我尝试在C#上使用RichTextBox,但发现它对于处理数千行长的文本来说太慢了。经过一番谷歌搜索后,我发现这是因为默认情况下.net使用RichEdit 2.0,而解决方案是改为使用RichEdit 5.0。

C#RichEditBox具有极慢的性能(加载4分钟),已解决

它工作正常,文本显示的时间是几秒钟,而不是几分钟。但是,作为那种不关心个人项目兼容性的人,我想找到RichEdit的更高版本。我发现最新版本是8.0,整个版本都作为riched20.dll发行,部分包含在msftedit.dll中。

http://blogs.msdn.com/b/murrays/archive/2006/10/14/richedit-versions.aspx

http://blogs.msdn.com/b/murrays/archive/2012/03/03/richedit-8-0-preview.aspx

但是,msdn的文档以4.1停止,(我认为是)该项目的一名开发人员声称他们不再在上述博客中提供公共文档。

https://msdn.microsoft.com/zh-CN/library/windows/desktop/bb787873(v=vs.85).aspx

到目前为止,我已经能够明确运行msftedit.dll的RichEdit 2.0和5.0,但是所有其他版本都使我难以理解。例如,尽管约翰·克伦肖(John Crenshaw)评论说RichEdit 6.0可以正常工作,但我却无法使用它。除上述msftedit-2.0和5.0组合以外的任何尝试都将导致Application.Run()出现“窗口类名称无效”错误。(该程序在C#中,但是我没有这样标记它,因为我担心这个问题可能不是C#特定的问题。)该代码几乎是第一个链接中解决方案的精确副本,如下所示:

class Textbox : RichTextBox
{
[DllImport("kernel32.dll", EntryPoint = "LoadLibraryW", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern IntPtr LoadLibraryW(string s_File);

public static IntPtr LoadLibrary(string s_File)
{
    IntPtr h_Module = LoadLibraryW(s_File);
    if (h_Module != IntPtr.Zero)
        return h_Module;

    int s32_Error = Marshal.GetLastWin32Error();
    throw new Exception("LoadLibrary Failed with: "+s32_Error);
}

protected override CreateParams CreateParams
{
    get
    {
        CreateParams i_Params = base.CreateParams;
        try
        {
            // Available since XP SP1
            LoadLibrary("MsftEdit.dll"); // throws

            i_Params.ClassName = "RichEdit50W";
        }
        catch
        {
            // Windows XP without any Service Pack.
        }
        return i_Params;
    }
}
Run Code Online (Sandbox Code Playgroud)

我所做的是将ClassName字符串更改为不同的数字,例如RichEdit60W。

我使用的是Windows 8.1,因此msftedit.dll最多应具有RichEdit 7.0或8.0(博客文章中的措词尚不清楚),但我无法达到它们。有什么办法可以纠正这个问题,还是较新的版本是机密的?

Dav*_*idK 5

RichEdit 似乎主要是由 Microsoft 作为 Office 的一部分开发的,在不同时期仅包含版本 1.0、2.0、3.0 和 4.1。

其他更高版本的 RichEdit 可以在 Microsoft Office 安装中找到:如果安装了 Office,则必须从“程序文件”下的位置显式地 LoadLibrary() 它们。如果未安装 Office,那么您就不走运了:裸露 Windows 中不存在这些其他版本,并且没有重新分发许可证允许您将它们与您编写的任何适当版本一起分发。

所以,基本上,你运气不好。对不起。


Han*_*ant 5

我的机器上有 RichEdit 8.0 版,类名 RICHEDIT60W。它存储在 C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\RICHED20.DLL 中。当我为它编写包装器时它工作得很好:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.ComponentModel;

class RichEdit80 : RichTextBox {
    protected override CreateParams CreateParams {
        get {
            if (moduleHandle == IntPtr.Zero) {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86);
                path = System.IO.Path.Combine(path, @"Microsoft Shared\OFFICE15\RICHED20.DLL");
                moduleHandle = LoadLibrary(path);
                if ((long)moduleHandle < 0x20) throw new Win32Exception(Marshal.GetLastWin32Error(), "RichEdit control appears to be missing");
            }
            CreateParams createParams = base.CreateParams;
            createParams.ClassName = "RichEdit60W";
            if (this.Multiline) {
                if (((this.ScrollBars & RichTextBoxScrollBars.Horizontal) != RichTextBoxScrollBars.None) && !base.WordWrap) {
                    createParams.Style |= 0x100000;
                    if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None) {
                        createParams.Style |= 0x2000;
                    }
                }
                if ((this.ScrollBars & RichTextBoxScrollBars.Vertical) != RichTextBoxScrollBars.None) {
                    createParams.Style |= 0x200000;
                    if ((this.ScrollBars & ((RichTextBoxScrollBars)0x10)) != RichTextBoxScrollBars.None) {
                        createParams.Style |= 0x2000;
                    }
                }
            }
            if ((BorderStyle.FixedSingle == base.BorderStyle) && ((createParams.Style & 0x800000) != 0)) {
                createParams.Style &= -8388609;
                createParams.ExStyle |= 0x200;
            }
            return createParams;
        }
    }

    private static IntPtr moduleHandle;

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    static extern IntPtr LoadLibrary(string lpFileName);
}
Run Code Online (Sandbox Code Playgroud)

没有经过彻底测试。希望你对这段代码感到非常不舒服,它真的只够用于测试目的,看看你是否领先。DLL 的路径当然是大红旗,当您的机器上没有 Office 2013 时,您必须更改它。要求用户在他的机器上安装正确的 Office 版本,只有当您对将要运行的程序的机器有适当的控制时才会有效。当 LoadLibrary() 失败时使用回退路径在技术上是可能的。

这个特定版本的作用以及它如何与工具箱中的默认 RichTextBox 不兼容,很难进行逆向工程。粗略的猜测是“与Word更兼容”。 例如,后来的 RichEdit 版本更好地支持数学方程。只有通过彻底的测试才能找出答案。最好坚持使用 msftedit.dll