1 回答
TA贡献1836条经验 获得超5个赞
在 Windows 窗体项目中添加一个WebBrowser组件到您的窗体中,然后您可以javascript像下面这样运行:
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.DocumentText =
"<html><head><script>" +
@"function makeLine(azimuth, radius, length)
{
var svg = document.getElementById('icon');
let circumference = radius * 2 * Math.PI;
let line = document.createElementNS(svg.namespaceURI, 'circle');
line.setAttribute('r', radius);
line.setAttribute('stroke-dasharray', length + ' ' + circumference);
line.setAttribute('transform', 'rotate(' + azimuth + ')');
svg.appendChild(line);
return svg.outterHtml; //Note: this return line should be added to your code
}"
+ "</script></head><body><svg id=\"icon\" viewBox=\"-100 -100 200 200\"></svg></body></html>";
}
private void button1_Click(object sender, EventArgs e)
{
var result = webBrowser1.Document.InvokeScript("makeLine", new object[] { 300, 93, 110 });
var svg = "<?xml version=\"1.0\" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>";
File.WriteAllText("C:\\a.svg", svg + result.ToString());
}
添加回答
举报