StrokeCollection.GetBounds 方法

定义

返回集合中笔画的边界。

public:
 System::Windows::Rect GetBounds();
public System.Windows.Rect GetBounds ();
member this.GetBounds : unit -> System.Windows.Rect
Public Function GetBounds () As Rect

返回

Rect

包含 Rect 中笔画的边界的 StrokeCollection

示例

下面的示例演示如何获取控件的 StrokeCollection 边界并将其绘制到控件上。 此示例假定有一个 InkCanvas 调用 inkCanvas1

public void GetBounds()
{
    Rect bounds = inkCanvas1.Strokes.GetBounds();

    Rectangle boundsShape = new Rectangle();
    boundsShape.Width = bounds.Width;
    boundsShape.Height = bounds.Height;
    boundsShape.Stroke = Brushes.Red;

    InkCanvas.SetTop(boundsShape, bounds.Top);
    InkCanvas.SetLeft(boundsShape, bounds.Left);

    inkCanvas1.Children.Add(boundsShape);
}
Public Sub GetBounds()
    Dim bounds As Rect = inkCanvas1.Strokes.GetBounds()

    Dim boundsShape As Rectangle = New Rectangle()
    boundsShape.Width = bounds.Width
    boundsShape.Height = bounds.Height
    boundsShape.Stroke = Brushes.Red

    InkCanvas.SetTop(boundsShape, bounds.Top)
    InkCanvas.SetLeft(boundsShape, bounds.Left)

    inkCanvas1.Children.Add(boundsShape)
End Sub

注解

该方法 GetBounds 返回一个 Rect 返回呈现的外观 Stroke。 例如,如果 Stroke 10 个显示独立像素 (DIP) 宽,则 Rect 包括整个 Stroke宽度。

适用于