Articles in this section
Category / Section

How do I programmatically create symbols defined in WinForms Diagram?

3 mins read

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

The Essentia 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.
c) Using the InsertNodesCmd for programmatic insertion.


Conclusion

I hope you enjoyed learning about how to programmatically create symbols defined in WinForms Diagram.

You can refer to our WinForms Diagram feature tour page to learn about its other groundbreaking feature representations. You can also explore our WinForms Diagram documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusio, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


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