Partilhar via


Customization: Setting EndPoint positions on a Connector.

There was a question on our forums about how to set the end points of a Connector programmatically, rather than having them calculated dynamically. This is possible to do in DSL Tools with some custom code.

You can set the FromEndPoint and ToEndPoint properties on Connector. However, end points also have a fixed flag. By default, the FixedFrom and FixedTo properties are set to VGFixedCode.Algorithm, so the routing engine comes along later, during the Transaction.Commit, and wipes out the From/ToEndPoints that you set. To use the end point you specified, you also need to set those fixed properties to VGFixedCode.Caller. Then, the routing engine will use the end points you provide.

Here's a code example below that makes the lines route to specific points:

 public partial class ExampleConnector : Connector
 {
  public override void OnShapeInserted()
  {
   base.OnShapeInserted();

   using (Transaction t = this.Store.TransactionManager.BeginTransaction("ChangeFromEndPoint"))
   {
    this.FromEndPoint = new PointD(this.FromShape.AbsoluteBounds.Center.X,
              this.FromShape.AbsoluteBounds.Top);
    this.FixedFrom = Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.VGFixedCode.Caller;

    this.ToEndPoint = new PointD(this.ToShape.AbsoluteBounds.Left,
              this.ToShape.AbsoluteBounds.Center.Y);
    this.FixedTo = Microsoft.VisualStudio.Modeling.Diagrams.GraphObject.VGFixedCode.Caller;

    t.Commit();
   }
  }
 }

Doing so produces Connectors that look like this (notice that all connectors starte and end at the same point of either side):

Typically, free-form connectors look like the following:

And, as an added bonus, I got to use the new image gallery features on MSDN blogs to show the pretty pictures. :)