Ok I think I got most of what the post said. Here is my latest version of the class.
When saving diagram I am still getting the error.
using System;
using System.Drawing;
using Syncfusion.Windows.Forms.Diagram;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
namespace HomeConductor.App.Composer
{
///
/// Summary description for DeviceSymbol.
///
[Serializable()]
public class DeviceSymbol : Symbol
{
public DeviceSymbol(string filename)
{
ImageFileName = filename;
CreateSymbol();
}
public void CreateSymbol()
{
//////////////////////////////////////////////////////////////////
// Add child nodes to the symbol programmatically
//////////////////////////////////////////////////////////////////
InsertNodesCmd cmd = new InsertNodesCmd();
System.Drawing.GraphicsUnit graphunit = new GraphicsUnit();
graphunit = GraphicsUnit.Pixel;
System.Drawing.Imaging.Metafile file = new System.Drawing.Imaging.Metafile(ImageFileName);
System.Drawing.RectangleF rect = new RectangleF(100, 100, file.Width, file.Height);
MetafileNode metaFileNode = new MetafileNode(file, RectangleF.Inflate(rect, 0, 0), graphunit);
this.AppendChild(metaFileNode);
//Add these lines to DeviceSymbol''s Constructor
this.Ports.Add(new AnchoredPort(this, BoxPosition.TopLeft));
this.Ports.Add(new AnchoredPort(this, BoxPosition.TopRight));
this.Ports.Add(new AnchoredPort(this, BoxPosition.TopCenter));
this.Ports.Add(new AnchoredPort(this, BoxPosition.BottomLeft));
this.Ports.Add(new AnchoredPort(this, BoxPosition.BottomCenter));
this.Ports.Add(new AnchoredPort(this, BoxPosition.BottomRight));
this.Ports.Add(new AnchoredPort(this, BoxPosition.MiddleLeft));
this.Ports.Add(new AnchoredPort(this, BoxPosition.MiddleRight));
foreach (AnchoredPort port in this.Ports)
{
// loads the circle crosshair instead of the x port
port.Load(PortVisuals.CirclePort);
port.Visible = false;
}
}
protected string ImageFileName;
///
/// Copy constructor.
///
///
public DeviceSymbol(DeviceSymbol src) : base(src)
{
}
///
/// Serialization constructor for the MySymbol class.
///
///
Serialization state information
///
Streaming context information
protected DeviceSymbol(SerializationInfo info, StreamingContext context) : base(info, context)
{
// The Serialization constructor is invoked during deserialization or during a drag & drop operation.
// If the MySymbol type has serializable members, then initialize them with the serialized data
// obtained from the SerializationInfo param
// Read the bClrFlag member value from the SerializationInfo object
this.ImageFileName = info.GetString("ImageFileName");
}
// Override SymbolBase.GetObjectData() and populate the SerializationInfo param
// with the data (if any) that belongs to the MySymbol type . This data will be
// serialized as a part of the Symbol object.
protected override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
// Populate the SerializationInfo object with the bClrFlag member data
info.AddValue("ImageFileName", this.ImageFileName);
}
}
}