ShapeElement.DoFoldToShape Method

Calculates the point where a connector will touch the perimeter of a shape. Override this if you define a non-rectangular shape.

Namespace:  Microsoft.VisualStudio.Modeling.Diagrams
Assembly:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams.11.0 (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.11.0.dll)


Public Overridable Function DoFoldToShape ( _
    potentialPoint As PointD, _
    vectorEndpoint As PointD _
) As PointD
public virtual PointD DoFoldToShape(
    PointD potentialPoint,
    PointD vectorEndpoint
virtual PointD DoFoldToShape(
    PointD potentialPoint, 
    PointD vectorEndpoint
abstract DoFoldToShape : 
        potentialPoint:PointD * 
        vectorEndpoint:PointD -> PointD  
override DoFoldToShape : 
        potentialPoint:PointD * 
        vectorEndpoint:PointD -> PointD
public function DoFoldToShape(
    potentialPoint : PointD, 
    vectorEndpoint : PointD
) : PointD


  • vectorEndpoint
    Type: Microsoft.VisualStudio.Modeling.Diagrams.PointD

    The direction of the connector. Another point on the line, relative to the potentialPoint. For a horizontal connector, the Y coordinate will always be 0, and for a vertical connector the X coordinate is always 0. The other coordinate has an arbitrary value whose sign indicates the direction of the center of the shape from the potentialPoint. For a straight connector, the ratio of X and Y gives the slope of the line, and their values are arbitrary.

Return Value

Type: Microsoft.VisualStudio.Modeling.Diagrams.PointD
The point where the connector should terminate.


This method is called to determine the point on the boundary of a shape at which a connector should be terminated. By default for a rectangular shape, the point will be on the bounding box of the shape. But if you define a class of shape that has an unusual geometry, for example an icon shape in which the icon is not rectangular, then this default behavior might leave a gap between the connector and the actual edge of your shape. You can override this method to calculate the actual point on the edge of your shape at which the connector should terminate.

Fold to shape


In this example, the author has specified an icon shape in DSL Definition, and supplies an icon in which the picture has an elliptical outline. By default, connectors terminate at the bounding box, but this looks unsatisfactory when the termination points are not in the middle of a side. DoFoldToShape should therefore calculate where the connector will cross the ellipse. Fortunately, there is a utility function that performs this task for a circle: we do not need to find our high school geometry books. We can adapt the utility function to work for an ellipse by multiplying the inputs by a factor and dividing the output by the same factor.

public partial class MyEllipticalIconShape
  public override PointD DoFoldToShape(PointD potentialPoint, PointD vectorEndpoint)
    double width = this.Bounds.Width;
    double height = this.Bounds.Height;
    double k = width / height; // transform from ellipse to circle
    // This utility method folds to a circle. But we have an ellipse, so
    // we adjust the Y values of the inputs:
    PointD result = ShapeGeometry.SnapToCircle(
        new PointD(width / 2, width / 2), // center, relative to shape
        width / 2, // radius of circle
        new PointD(vectorEndpoint.X, vectorEndpoint.Y * k),
        new PointD(potentialPoint.X, potentialPoint.Y * k));
    // Transform the circular result back to the ellipse:
    return new PointD(result.X, result.Y / k); 

.NET Framework Security

See Also


ShapeElement Class

Microsoft.VisualStudio.Modeling.Diagrams Namespace