Articles in this section
Category / Section

How do I programmatically create the symbols defined in a symbol palette file?

2 mins read

How do I programmatically create the symbols defined in a symbol palette file?

The Essential Diagram symbol palette file (*.edp file) is a serialized representation of the Syncfusion.Windows.Forms.Diagram.SymbolPalette class, a special type of diagram model that contains a collection of SymbolModel objects. The SymbolPalette can be retrieved from the palette file by deserializing the palette file as shown below,

C#

SymbolPalette palette = null;
FileStream iStream = null;
if (File.Exists(filename))
{
iStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
SoapFormatter formatter = new SoapFormatter();
formatter.Binder = Syncfusion.Runtime.Serialization.AppStateSerializer.CustomBinder;
formatter.AssemblyFormat = FormatterAssemblyStyle.Simple;
try
{
System.AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Syncfusion.DiagramBaseAssembly.AssemblyResolver);
palette = (SymbolPalette) formatter.Deserialize(iStream);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
palette = null;
}
finally
{
iStream.Close();
System.AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(Syncfusion.DiagramBaseAssembly.AssemblyResolver);
}
}

 

VB

Dim palette As SymbolPalette = Nothing
Dim iStream As FileStream = Nothing
If File.Exists(filename) Then
iStream = New FileStream(filename, FileMode.Open, FileAccess.Read)
Dim formatter As SoapFormatter = New SoapFormatter
formatter.Binder = Syncfusion.Runtime.Serialization.AppStateSerializer.CustomBinder
formatter.AssemblyFormat = FormatterAssemblyStyle.Simple
Try
AddHandler System.AppDomain.CurrentDomain.AssemblyResolve, AddressOf Syncfusion.DiagramBaseAssembly.AssemblyResolver
palette = CType(formatter.Deserialize(iStream), SymbolPalette)
Catch ex As Exception
MessageBox.Show(ex.Message)
palette = Nothing
Finally
iStream.Close()
RemoveHandler System.AppDomain.CurrentDomain.AssemblyResolve, AddressOf Syncfusion.DiagramBaseAssembly.AssemblyResolver
End Try
End If
 

 

Once the SymbolPalette has been loaded, the SymbolPalette.Nodes property may be used to get hold of the collection of SymbolModels in that palette. SymbolModels serve as the design-time representation of symbols, and the symbol itself can be created using the SymbolModel.CreateInstance() method. The symbol can then be added to the diagram by a) Directly adding it to the diagram's Model.Nodes collection, b) Using the InsertSymbolTool or InsertNodeTool for interactive insertion, or c)Using the InsertNodesCmd for programmatic insertion.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment