BoundsRules 类

约束可以找到的形状及如何对其调整的规则。

继承层次结构

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

命名空间:  Microsoft.VisualStudio.Modeling.Diagrams
程序集:  Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0(在 Microsoft.VisualStudio.Modeling.Sdk.Diagrams.12.0.dll 中)

语法

声明
<SerializableAttribute> _
Public MustInherit Class BoundsRules
[SerializableAttribute]
public abstract class BoundsRules

BoundsRules 类型公开以下成员。

构造函数

  名称 说明
受保护的方法 BoundsRules

页首

方法

  名称 说明
公共方法 Equals 确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法 GetCompliantBounds 调整建议的大小和位置,以便其符合此边界规则。用户在移动鼠标时重复调用。虚影形状给用户显示了符合边界。
公共方法 GetHashCode 作为默认哈希函数。 (继承自 Object。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

备注

“绑定规则” 是定义形状的大小和位置限制的类。 当用户拖动时,形状的角或端GetCompliantBounds 重复调用。

有关详细信息,请参阅BoundsRules 约束形状位置和大小

示例

以下示例约束矩形为一组固定大小,水平或垂直。 当用户拖动角或边时,轮廓将在二个允许的有关高度和宽度的配置之间翻转。

记下该位置和大小可能被约束,如果您希望。

绑定规则是,类实例,则形状创建:

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));
} } }

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

请参阅

参考

Microsoft.VisualStudio.Modeling.Diagrams 命名空间

其他资源

BoundsRules 约束形状位置和大小