BoundsRules Class
Defines limits on the size and location of a shape.
Namespace: Microsoft.VisualStudio.Modeling.Diagrams
Assembly: Microsoft.VisualStudio.Modeling.Sdk.Diagrams (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.dll)
Syntax
'Declaration
<SerializableAttribute> _
Public MustInherit Class BoundsRules
'Usage
Dim instance As BoundsRules
[SerializableAttribute]
public abstract class BoundsRules
[SerializableAttribute]
public ref class BoundsRules abstract
public abstract class BoundsRules
Remarks
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.
Examples
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: BoundsRule
{
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));
} } }
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules
Microsoft.VisualStudio.Modeling.Diagrams.AvoidCornerRule
Microsoft.VisualStudio.Modeling.Diagrams.DefaultBoundsRules
Microsoft.VisualStudio.Modeling.Diagrams.KeepInParentRule
Microsoft.VisualStudio.Modeling.Diagrams.NoBoundsRules
Microsoft.VisualStudio.Modeling.Diagrams.PortMovementRule
Microsoft.VisualStudio.Modeling.Diagrams.SnapToGridRule
Microsoft.VisualStudio.Modeling.Diagrams.SnapToPerimeterFollowingRotationRule
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
Microsoft.VisualStudio.Modeling.Diagrams Namespace
Change History
Date |
History |
Reason |
---|---|---|
Added description and example. |
Customer feedback. |