RichTextBox (.NET Winforms) 问题(或替代方案)

发布于 2024-08-02 02:31:29 字数 771 浏览 9 评论 0原文

我对 .Net 的 RichTextBox 控件。 它似乎不支持表格单元格格式,这很有趣,因为大多数时候我创建表格时我希望单元格内容右对齐(数字、货币)。

如果我尝试在 RichTextBox 中打开写字板文档,它会忽略(实际上删除)单元格对齐命令。 我尝试了几种解决方法但没有成功。

  1. 有人能想出解决这个问题的办法吗? (不使用固定宽度的字体和空格)这将是最好的解决方案,因为其他代码已经工作正常,所以如果只需要一个肮脏的黑客,那就太好了。

  2. 或者您可以推荐 .Net 富文本编辑器的开源替代品吗? 我需要一个可以嵌入 Windows 表单并以编程方式访问内容的用户控件(创建内容或附加内容)。 我在网络上搜索了一段时间,但只找到了网络(Ajax/Javascript)控件。

  3. 还有一些我可以使用的 HTML WYSIWYG 编辑器,但它们基本上都是使用 MSHTML 嵌入和编辑的 IE 浏览器,在 Winforms 应用程序中使用它感觉有点奇怪(也许我错了)。 在这种情况下,我们将需要一些额外的时间来实现 HTML 内容生成器 - 尽管它比 RTF 恕我直言更容易阅读和生成。

  4. 你们觉得什么最适合这个目的?

I have a problem with .Net's RichTextBox control. It seems that it doesn't support table cell formatting, which is funny because most of the time I create tables I want the cell contents to be right-aligned (numbers, currency).

If I try to open a WordPad document in RichTextBox, it ignores (and actually removes) the commands for cell alignment. I tried several workarounds but didn't succeed.

  1. Can anyone think of an idea to fix this? (without using fixed-width fonts and spaces) This would be the best solution since other code is working fine already, so if only thing needed is a dirty hack, it would be great.

  2. Or is there an open source alternative for .Net Rich Text Editor you can recommend? I need a user control I can embed in my Windows form and access the contents programmatically (create content, or append something). I have searched the web for some time but found only web (Ajax/Javascript) controls.

  3. There are also HTML WYSIWYG editors which I could use, but they are all basically a IE browser embedded and edited using MSHTML, and it feels a bit strange to have that in a Winforms app (maybe I am wrong). And in that case we will need some extra time to implement a content generator for HTML - although it's much easier to read and generate than RTF IMHO.

  4. What do you guys find best for this purpose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2024-08-09 02:31:29

如果您仍然沿着 .net winforms 路径前进,然后继承 RichTextBox 并添加以下代码,它将把 RichTextBox 转换为“可用”的内容:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);

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

源自 此处

祝你今天过得愉快:)

If you are still going down the .net winforms path then inherit from RichTextBox and add the following code, it will transform the RichTextBox into something "useable":

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);

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

Sourced from here.

Have a nice day:)

萤火眠眠 2024-08-09 02:31:29

3.我也可以使用 HTML WYSIWYG 编辑器,但它们基本上都是使用 MSHTML 嵌入和编辑的 IE 浏览器,在 Winforms 应用程序中使用它感觉有点奇怪(也许我错了)。

我编写了一个 HTML WYSIWYG 编辑器:ModelText HTML Control for .NET。 它是纯托管代码,不依赖于浏览器; 它导出 .NET API,使您可以通过编程方式访问其内容。

即将发布的下一个版本(几天后)将支持单元格对齐(通过支持 CSS“text-align”属性)。

3.There are also HTML WYSIWYG editors which I could use, but they are all basically a IE browser embedded and edited using MSHTML, and it feels a bit strange to have that in a Winforms app (maybe I am wrong).

I've written a HTML WYSIWYG editor: the ModelText HTML Control for .NET. It's pure managed code, with no dependency on a browser; it exports .NET APIs, which let you access its contents programmatically.

The next version to be released (in a few days from now) will support cell alignment (by supporting the CSS "text-align" property).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文