Is it possible to programmatically change the geometry of the node(s) within a Symbol?
Is it possible to programmatically change the geometry of the node(s) within a Symbol?
The Syncfusion.Windows.Forms.Diagram.ILocalPoints interface that all Essential Diagram Shape objects implement can be used to dynamically access and change the geometry of the nodes that make up a symbol. The following code shows how to programmatically change the length of a Line node contained within a custom defined symbol.
C#
public class MySymbol : Symbol { public MySymbol() { // Custom symbol initialization // Original line segment in the symbol spanning points (20,30) to (40,30) this.innerLine = new Line(new PointF(20,30), new PointF(40,30)); this.AppendChild(this.innerLine); } // Changing the geometry of a node in the symbol public void IncreaseLineLength() { // Use the ILocalPoints interface to dynamically access and change the line geometry // The following code changes the line's end point from (40,30) to (60,30) IServiceProvider svcprovider = this.innerLine as IServiceProvider; ILocalPoints localpoints = (ILocalPoints)svcprovider.GetService(typeof(ILocalPoints)); Debug.Assert(svcprovider != null); PointF[] pts = localpoints.GetPoints(); Trace.WriteLine(pts[0].ToString(), pts[1].ToString()); // Set the new end point of the line to be PointF(60,30); localpoints.SetPoint(1, new PointF(60,30)); } }
VB
Public Class MySymbol Inherits Symbol Public Sub New() ' Custom Symbol initialization ' Original line segment in the custom symbol spanning points (20,30) to (40,30) Me.innerLine = New Line(New PointF(20, 30), New PointF(40, 30)) Me.AppendChild(Me.innerLine) End Sub Public Sub IncreaseLineLength() ' Use the ILocalPoints interface to dynamically access and change the line geometry ' The following code changes the line's end point from (40,30) to (60,30) Dim svcprovider As IServiceProvider = Me.innerLine Dim localpoints As ILocalPoints = CType(svcprovider.GetService(GetType(ILocalPoints)), ILocalPoints) Debug.Assert( Not (svcprovider Is Nothing)) Dim pts As PointF() = localpoints.GetPoints() Trace.WriteLine(pts(0).ToString(), pts(1).ToString()) ' Set the new end point of the line to be PointF(60,30) localpoints.SetPoint(1, New PointF(60, 30)) End Sub End Class 'MySymbol
Referring to the class reference documentation on the Syncfusion.Windows.Forms.Diagram.ILocalPoints interface will give a better idea on how to go about using it.