【问题标题】:Display XmlDocument (SVG) in WInForm Webbrowser在 WInForm Webbrowser 中显示 XmlDocument (SVG)
【发布时间】:2018-03-12 14:42:06
【问题描述】:

我在我的 winform 应用程序中创建了一个 XmlDocument

 Public Xdoc As New XmlDocument

其中包含 SVG 文件的数据。我想在网络浏览器中显示这个 SVG 文件,但我不知道怎么做。

有人可以帮我解决这个问题吗?

这是我到目前为止的代码(但它不能完成工作)

   Public Sub Webbrowerstest()

    Dim text As String = Xdoc.InnerXml
    InitializeComponent()
    WebBrowser1.DocumentText = text

    End Sub

编辑: 所以我修改了我的代码,我仍然得到一个 Empty webbrowser 控件这是我正在使用的当前代码:我检查了 Text 和 Xdoc 的内容,如果我将其导出为文件并在我的普通浏览器中打开它,SVG 正在工作.

ublic Sub Webbrowerstest()

    Dim text As String = Xdoc.InnerXml
    InitializeComponent()
    WebBrowser1.DocumentText = "<!DOCTYPE HTML><html><head><meta http-equiv=""x-ua-compatible"" content=""IE=11""><meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8""><title>SVG sample</title> <style type=""text/css""></style></head><body><div>" & text & "</div></body></html>"

End Sub

【问题讨论】:

标签: xml vb.net svg webbrowser-control


【解决方案1】:

在 Web 浏览器控件中使用 SVG 的方式与在 Web 浏览器中使用它的方式相同。

您将 SVG 代码嵌入到 svg 标记中。

这里是一些示例 HTML 代码,您可以从 Web 浏览器控件导航到这些代码

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="x-ua-compatible" content="IE=11">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>SVG sample</title>
    <style type="text/css">
    </style>
</head>
<body>
    <div>
        <svg height="100" width="100">
            <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
            Sorry, your browser does not support inline SVG.
        </svg>
    </div>
</body>
</html>

这是输出:

【讨论】:

  • 好吧,所以我编辑了我的代码,它仍然显示并清空 webbrowser 控件以获取更多信息,请查看问题中的编辑
  • 好的,所以我删除了我的 webbrowser 控件并再次添加它,现在它正在使用我上面发布的代码。唯一的问题是 SVG 仅显示在浏览器的一小部分中,而不是在整个表面上展开。
猜你喜欢
  • 1970-01-01
  • 2014-09-25
  • 1970-01-01
  • 1970-01-01
  • 2012-09-25
  • 1970-01-01
  • 2013-04-19
  • 2013-08-24
  • 1970-01-01
相关资源
最近更新 更多