Delen via


NodeShape.BoundsRules Property

Bounds rules constrain how the user can update the size and position of the bounding rectangle. Override to return a BoundsRules.

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

Syntax

'Declaration
Public Overridable ReadOnly Property BoundsRules As BoundsRules
public virtual BoundsRules BoundsRules { get; }
public:
virtual property BoundsRules^ BoundsRules {
    BoundsRules^ get ();
}
abstract BoundsRules : BoundsRules with get 
override BoundsRules : BoundsRules with get
function get BoundsRules () : BoundsRules

Property Value

Type: Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules

Remarks

Override BoundsRules in your shape class to constrain how the user can move or re-size a shape. For example, you could prevent the user from moving a shape out of or into a particular area, or you could limit the width and height to specific ranges or proportions. The rules are applied while the user is dragging the shape or its sides or corners, and the user sees the movements of the ghost shape being restricted according to your rules.

This property should return an instance of a class that implements BoundsRules. Your BoundsRules implementation should have a method M:Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules.GetCompliantBounds(Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement,Microsoft.VisualStudio.Modeling.Diagrams.RectangleD). This method is called repeatedly while the user drags the shape. The method is provided with the proposed bounds, which represent the size and position that the user is trying to set. It should return the bounds permitted by your rule.

No constraint is applied if BoundsRules returns nulla null reference (Nothing in Visual Basic).

Note

If you want to respond to a change of size or position after it has occurred, for example to adjust the positions of adjacent shapes, create a ChangeRule to observe the AbsoluteBounds property. See the example in AbsoluteBoundsDomainPropertyId. If you want to update values outside the Store, override OnAbsoluteBoundsChanged.

Examples

This example constrains the shapes of class MyShape to have a specified minimum width, and a specific ration of height to width.

// MyShape is defined in DSL Definition.
public partial class MyShape 
{
    public override BoundsRules BoundsRules
    {
        get
        {
            return new MyShapeBoundsRule();
        }
    }
}
public class MyShapeBoundsRule : BoundsRules
{
    public override RectangleD GetCompliantBounds(ShapeElement shape, RectangleD proposedBounds)
    {
       // Do not modify bounds if reading from file.
        if (shape.Store.InSerializationTransaction)
          return proposedBounds;
        MyShape myShape = shape as MyShape;
        if (myShape == null) return proposedBounds;
        RectangleD approvedBounds = new RectangleD();
        // In this rule, any Location is OK:
        approvedBounds.Location = proposedBounds.Location;
        // But the height and width are constrained:
        approvedBounds.Height = Math.Max(proposedBounds.Height, 1.0);
        approvedBounds.Width = approvedBounds.Height * 1.618;
        return approvedBounds;
    }    
 }

.NET Framework Security

See Also

Reference

NodeShape Class

Microsoft.VisualStudio.Modeling.Diagrams Namespace