语言

StrokeCollection.GetBounds 方法

定义

返回集合中笔划的边界。

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

返回

一个包含笔划边界的 RectAStrokeCollection。

示例

下面的示例演示如何获取控件的 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。

适用于