Aracılığıyla paylaş


BoundsRules şekli konumunu ve boyutunu sınırlamak

A Sınırları kural sınırları boyutu ve bir şeklin konumunu tanımlayan bir sınıftır.Bir kullanıcı bir şekil veya köşeler ya da bir şeklin kenarlarına sürükleme sırasında sürekli olarak adlandırılan bir yöntemidir.

Aşağıdaki örnek, dikdörtgen şeklinde sabit boyuta, yatay veya dikey bir çubuk olarak sınırlar.Kullanıcı köşeler veya kenarı sürüklendiğinde, anahat iki izin verilen konfigürasyonları yükseklik ve Genişlik arasında çevirir.

Sınırları olan türetilmiş bir sınıf tarafından kural BoundsRules.Kural örneği şeklinde oluşturulur:

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

İsterseniz konumu ve boyutu kısıtlanabilir dikkat edin.

Ayrıca bkz.

Başvuru

BoundsRules

Diğer Kaynaklar

Yanıtlama ve değişiklikleri yayılıyor