Using Adobe's SVG control from .NET

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:


© 2000 MecXpert