BoundsRules Class

 

Rules that constrain where a shape can be located and how it can be sized.

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


[SerializableAttribute]
public ref class BoundsRules abstract 

NameDescription
System_CAPS_pubmethodEquals(Object^)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetCompliantBounds(ShapeElement^, RectangleD)

Adjust a proposed size and position so that they are compliant with this bounds rule. Called repeatedly while the user moves the mouse. The ghost shape shows the user the compliant bounds.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

A Bounds Rule is a class that defines limits on the size and location of a shape. GetCompliantBounds is called repeatedly while a user is dragging a shape or the corners or sides of a shape.

For more information, see BoundsRules Constrain Shape Location and Size.

The following example constrains a rectangular shape to be a bar of fixed size, either horizontal or vertical. When the user drags the corners or sides, the outline flips between the two permitted configurations of height and width.

Notice that both the location and size can be constrained if you want.

The bounds rule is a class, and an instance is created in the shape:

using Microsoft.VisualStudio.Modeling.Diagrams; ...
public partial class BarShape
{
  /// <summary>
  /// Rule invoked when the user is resizing a shape.
  /// </summary>
  public override BoundsRules BoundsRules
  { get { return new BarBoundsRule(); } }
}
/// <summary>
/// Rule invoked when the user is changing a shape's outline.
/// Provides real-time mouse rubber-band feedback, so must work fast.
/// </summary>
public class BarBoundsRule: BoundsRules
{ 
  public override RectangleD GetCompliantBounds 
     (ShapeElement shape, RectangleD proposedBounds)
  {
    double thickness = 0.1;
    if (proposedBounds.Height > proposedBounds.Width)
    {
      // There is a minimum width for a shape; the width
      // will actually be set to the lesser of 
      // thickness and that minimum.
      return new RectangleD(proposedBounds.Location, 
            new SizeD(thickness, proposedBounds.Height));
    }
    else
    {
      // There is a minimum height for a shape; the 
      // height will actually be set to the lesser of 
      // thickness and that minimum.
      return new RectangleD(proposedBounds.Location, 
         new SizeD(proposedBounds.Width, thickness));
} } }

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: