Link color


We use nodes and links to present Power Network, links will be assigned to different colors to distinguish the area which links belongs to.
We used to create a new pen for the link, and set the new pen to desired color, like
public void SetLinkColor (Color Color)

Pen NewPen = (Pen)this.Pen.Clone();
NewPen.Color = Color;
this.Pen = NewPen;

This works fine.
Since we have huge number of links which we need to set color dynamically, this create new pen takes long cpu time. We try to improve this part. We try to change color of existing pen as
public void SetLinkColor (Color Color)
this.Pen.Color = Color;

But it does not work, all links being set to a single color, which is the color we assigned to the last link. We don’t understand why. Do we have to create a new pen for the link, and be able to set the new color?


Yes, this is documented–you should not modify a Pen or a Brush once it has been assigned to a pen or brush property of a GoObject.
Creating a new Pen is pretty quick, and it can be shared by all of the objects. Yes, you do need to set the Pen property for each GoShape, but one way or another that would need to be done anyway, since GoDiagram needs to know what parts of each view needs to be repainted.
The Processor sample application (GoDiagram Win) has a Timer that each tick creates a new Pen and then assigns it to all of the links in the document. This is how it animates the diagram, making it look like there is “stuff” going through the links.


Thanks, I will try to create a set of pens with different colors, when we need assign a new color to a link, just reassign the pen with that color to the link.