BoundsRules Class
Rules that constrain where a shape can be located and how it can be sized.
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
Namespace: Microsoft.VisualStudio.Modeling.Diagrams
Assembly: Microsoft.VisualStudio.Modeling.Sdk.Diagrams.10.0 (in Microsoft.VisualStudio.Modeling.Sdk.Diagrams.10.0.dll)
Syntax
'Déclaration
<SerializableAttribute> _
Public MustInherit Class BoundsRules
[SerializableAttribute]
public abstract class BoundsRules
[SerializableAttribute]
public ref class BoundsRules abstract
[<AbstractClass>]
[<SerializableAttribute>]
type BoundsRules = class end
public abstract class BoundsRules
The BoundsRules type exposes the following members.
Constructors
Name | Description | |
---|---|---|
BoundsRules |
Top
Methods
Name | Description | |
---|---|---|
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetCompliantBounds | 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. | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
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.
For more information, see BoundsRules Constrain Shape Location and Size.
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: 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));
} } }
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
Other Resources
BoundsRules Constrain Shape Location and Size
Change History
Date |
History |
Reason |
---|---|---|
June 2010 |
Added description and example. |
Customer feedback. |