Språk

StrokeCollection.GetBounds Metod

Definition

Returnerar gränserna för linjerna i samlingen.

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

Returer

A Rect som innehåller gränserna för linjerna i StrokeCollection.

Exempel

I följande exempel visas hur du hämtar gränserna för StrokeCollection och ritar dem på kontrollen. Det här exemplet förutsätter att det finns en InkCanvas som heter 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

Kommentarer

Metoden GetBounds returnerar en Rect som ser ut som den renderade Stroke. Om Stroke till exempel är 10 visa oberoende pixlar (DIP) bred, Rect innehåller hela bredden på Stroke.

Gäller för