【问题标题】:C# WebBrowser Document write and ExecCommandC# WebBrowser 文档写入和 ExecCommand
【发布时间】:2021-12-09 16:43:14
【问题描述】:

在尝试通过以下代码将 HTML 转换为 RTF 时

string html = "...."; // html content
RichTextBox rtbTemp = new RichTextBox();
WebBrowser wb = new WebBrowser();
wb.Navigate("about:blank");
wb.Document.Write(html);
wb.Document.ExecCommand("SelectAll", false, null);
wb.Document.ExecCommand("Copy", false, null);
rtbTemp.SelectAll();
rtbTemp.Paste();

这里 Document.Write(html);Document.ExecCommand 出现错误 这里需要 using 来克服这个问题是新的请指导我们

例如:using System.Windows.Controls;

这里是完整代码image full

【问题讨论】:

  • "getting error here" - 阅读 How to Ask 并显示实际错误以及您尝试过的错误。
  • 这里是完整代码i.stack.imgur.com/Is7MW.png
  • 为什么不直接右键单击(或Ctrl+.)错误,选择快速操作和重构并添加它建议的 using 语句?
  • sir @CodeCaster 显示错误,例如:CS1061 'object' 不包含'Write' 的定义,并且找不到接受'object' 类型的第一个参数的可访问扩展方法'Write'(是您缺少 using 指令或程序集引用?)
  • 现在有自己的 WebBrowser 类

标签: c# .net


【解决方案1】:

您正在使用 WPF WebBrowser 控件。

使用 WinForms 代替 System.Windows.Controlsusing System.Windows.Forms;

或查看 How can I get an HtmlElementCollection from a WPF WebBrowserHow to get HTML from WebBrowser control,将 WebBrowser.Document 转换为适当的类型,或将控件托管在 WPF 窗口中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2017-09-08
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多