NodeShape.BoundsRules 屬性
範圍規則限制的大小和位置,這個週框,使用者可以更新的方式。傳回 BoundsRules 的覆寫。
命名空間: Microsoft.VisualStudio.Modeling.Diagrams
組件: Microsoft.VisualStudio.Modeling.Sdk.Diagrams.11.0 (在 Microsoft.VisualStudio.Modeling.Sdk.Diagrams.11.0.dll 中)
語法
'宣告
Public Overridable ReadOnly Property BoundsRules As BoundsRules
public virtual BoundsRules BoundsRules { get; }
屬性值
型別:Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules
備註
在 BoundsRules 中覆寫您的圖形類別,以限制使用者可以移動的方式或 re-size 的圖形。比方說,您可以防止使用者移動的圖形超出或特定區域中,您也可以限制的寬度和高度,以特定的範圍或比例。使用者正在拖曳的圖形或側邊或角落,及使用者所看到的快慢程度根據您的規則來限制 「 幽靈車圖形時,會套用規則。
這個屬性應該傳回實作的類別的執行個體BoundsRules。您 BoundsRules 的實作應該要有一種方法M:Microsoft.VisualStudio.Modeling.Diagrams.BoundsRules.GetCompliantBounds(Microsoft.VisualStudio.Modeling.Diagrams.ShapeElement,Microsoft.VisualStudio.Modeling.Diagrams.RectangleD)。當使用者拖曳圖形時,就會重複呼叫這個方法。提供方法與提議的範圍中,表示使用者嘗試設定的位置與大小。它應該傳回您的規則所允許的範圍。
如果套用任何限制式BoundsRules會傳回nullnull 參考 (即 Visual Basic 中的 Nothing)。
![]() |
---|
如果您想要回應的大小或位置的變更發生後,例如若要調整相鄰圖形的位置建立 ChangeRule,以觀察 [AbsoluteBounds] 屬性。請參閱 AbsoluteBoundsDomainPropertyId 中的範例。如果您想要更新存放區以外的值,會覆寫OnAbsoluteBoundsChanged。 |
範例
本範例會限制類別具有指定的最小寬度,MyShape 的圖形和特定的 ration 的高度與寬度。
// 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。