如何在不丢失内容格式 VB.NET 的情况下将 RTF 文件加载到 RichTextBox [英] How to Load RTF file to RichTextBox without loosing content format VB.NET

查看:41
本文介绍了如何在不丢失内容格式 VB.NET 的情况下将 RTF 文件加载到 RichTextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 word 2013 创建的 .rtf 文件加载到 Richtextbox 中,但我的内容格式有问题..我已尝试此代码..

I'am trying to load .rtf file created by word 2013 into richtextbox, but i have problem with content format..i have try this code..

RichTextBox1.LoadFile(App_Path & "/Artikel/Profile/Info Num1.rtf", RichTextBoxStreamType.RichText)

内容显示但内容格式缺失...

the content displayed but the content format is missing...

然后我尝试你的代码......

then i try yhis code to...

Dim SR As StreamReader
SR = File.OpenText(App_Path & "/Artikel/Profile/Info Num1.rtf")
RichTextBox1.Rtf = SR.ReadToEnd
SR.Close()

内容显示和文字格式显示良好,但表格和图像不规则..

the content is displayed and text format is diplayed well but the table and image is irregular..

对于简单的问题,如何将 .rtf 文件加载到 Richtextbox 而不会丢失包括表格和图像格式在内的内容格式?

for simple question how to load .rtf file to richtextbox without loosing content format including table and image format?

推荐答案

您可能需要升级 RichTextBox 组件:

You probably need to upgrade your RichTextBox component:

public class RichBoxEx : RichTextBox {

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

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

并使用更安全的 Path.Combine 版本加载文件:

and load the file with the safer version of Path.Combine:

richBoxEx1.LoadFile(Path.Combine(App_Path, @"Artikel/Profile/Info Num1.rtf"));

某些功能将被删除,因为 RichTextBox 不支持页眉和页脚等.

Some features will get dropped, since the RichTextBox doesn't have support for Header and Footers, etc.

这篇关于如何在不丢失内容格式 VB.NET 的情况下将 RTF 文件加载到 RichTextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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