How do I change the color of a connector programmatically?

From within a menu handler I wish to change the color of all the connectors from a shape? ClassStyleSet seems to a protected class when I access it from a ShapeElement.
[168 byte] By [foleyp] at [2007-12-24]
# 1

You can write an internal method to change the pen color based on your own criteria. e.g. You can create a parital class for AggregrationColor class (a language based on ClassDiagram) and provide an internal method.

public partial class AggregationConnector
{

internal void SetConnectorColor ( System.Drawing.KnownColor color)
{
StyleSet classStyleSet = base.StyleSet;
DslDiagrams::PenSettings linePen = new DslDiagrams::PenSettings();
linePen.Color = global::System.Drawing.Color.FromKnownColor(color);
classStyleSet.OverridePen(DslDiagrams::DiagramPens.ConnectionLineDecorator, linePen);
classStyleSet.OverridePen(DslDiagrams::DiagramPens.ConnectionLine, linePen);

}
}

In your menu handler, you can find the right connect and call the SetConnectorColor method. When the diagram is being repainted, it will display the color you specified.

HTH

Microsoft Visual Studio Team.


PatrickTseng at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2

Thanks this solved the problem

Only 1 problem left - how to create an editable Domain Type (see other message)

foleyp at 2007-8-31 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified