在WInForm Webbrowser中显示XmlDocument(SVG)

时间:2018-03-12 14:42:07

标签: xml vb.net svg webbrowser-control

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

 Public Xdoc As New XmlDocument

包含SVG文件的数据。我想在webbrowser中显示这个SVG文件,但我无法弄清楚如何。

任何人都可以帮我解决这个问题吗?

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

   Public Sub Webbrowerstest()

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

    End Sub

编辑: 所以我修改了我的代码,我仍然得到一个空的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

1 个答案:

答案 0 :(得分:1)

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

您将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>

这是输出:

enter image description here