Note: With Adobe's SVG control 3.0 beta you need to do extra work - which will hopefully disappear. This version is here.
Anyone interested in using Adobe's SVG control from within .NET WinForms can start with the example provided here.
Here is the C# code (SvgHost.cs):
//------------------------------------------------------------------------------
// Hosting Adobe's SVG Viewer control .. (c) MecXpert
//------------------------------------------------------------------------------
namespace MecXpert.Svg {
using System;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using SVGVIEWLib;
class SvgHost : Form {
private AxSVGVIEWLib.AxSVGCtl svgCtl;
private string fileName;
public SvgHost(string fname) {
fileName = fname;
InitializeComponent();
}
private void InitializeComponent()
{
InitializeSvgControl();
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.ClientSize = new System.Drawing.Size(svgCtl.Size.Width+20,
svgCtl.Size.Height+30);
this.Text = "C# SvgHost";
}
private void InitializeSvgControl()
{
this.svgCtl = new AxSVGVIEWLib.AxSVGCtl();
this.svgCtl.BeginInit();
this.svgCtl.Location = new System.Drawing.Point(10, 10);
Controls.Add(this.svgCtl);
this.svgCtl.EndInit();
this.svgCtl.SRC = fileName;
ISVGDocument doc = this.svgCtl.getSVGDocument();
IDOMElement docElem = doc.documentElement;
this.svgCtl.Size = new System.Drawing.Size(Convert.ToInt32(docElem.getAttribute("width")),
Convert.ToInt32(docElem.getAttribute("height")));
}
[STAThread]
public static int Main(String[] args)
{
string filename;
if (args.Length == 1)
{
filename = (Path.GetFullPath(args[0]));
if (File.Exists(filename))
Application.Run(new SvgHost("file://" + filename));
else
Console.Write("File '" + filename + "' does not exist!\n");
}
else
Console.Write("Usage: SvgHost <filename>\n");
return 0;
}
}
}
Follow these steps to get it up and running:
SvgHost.cs to any directory, say file://c:/SvgNetHost.c:/SvgNetHost.c:/winnt is your windows directory, enter the command:Cmd> aximp "c:\winnt\system32\Adobe\SVG Viewer\svgcontrol.dll"SVGVIEWLib.dll and AxSVGVIEWLib.dll.SvgHost.cs by:Cmd> csc SvgHost.cs -r:SVGVIEWLib.dll -r:AxSVGVIEWLib.dllSvgHost.exe executable file.Cmd> SvgHost sierpinski.svg
© 2000
MecXpert