StrokeCollection.GetBounds Method

Returns the bounds of the strokes in the collection.

Namespace:  System.Windows.Ink
Assembly:  System.Windows (in System.Windows.dll)

public Rect GetBounds()

Return Value

Type: System.Windows.Rect
A Rect that contains the bounds of the strokes in the StrokeCollection.

Do not attempt to set values in the returned Rect. It should be used for reference only.

There are various scenarios for using the returned Rect. The Rect can be used as input for a RectangleGeometry that displays a bounding box in the user interface, or it can be used to check for intersecting strokes or other types of hit-testing.

The following code example demonstrates the GetBounds method of the StrokeCollection object. After a stroke is drawn, a bounding box that surrounds the stroke is displayed.

Run this sample

Stroke MyStroke;
Rectangle MyRectangle = null;

//A new stroke object named MyStroke is created. MyStroke is added to the StrokeCollection of the InkPresenter named MyIP
private void MyIP_MouseLeftButtonDown(object sender, MouseEventArgs e)
    StylusPointCollection MyStylusPointCollection = new StylusPointCollection();
    MyStroke = new Stroke(MyStylusPointCollection);


//StylusPoint objects are collected from the MouseEventArgs and added to MyStroke
private void MyIP_MouseMove(object sender, MouseEventArgs e)
    if (MyStroke != null)

//GetBounds() method of the StrokeCollection is used to draw a rectangular boundary around the StrokeCollection
private void MyIP_LostMouseCapture(object sender, MouseEventArgs e)
    Rect MyRect = new Rect();
    MyRect = MyIP.Strokes.GetBounds();
    if (MyRectangle == null)
        MyRectangle = new Rectangle();
    MyRectangle.Height = MyRect.Height;
    MyRectangle.Width = MyRect.Width;
    Thickness MyThickness = new Thickness(MyRect.X, MyRect.Top, 0, 0);
    MyRectangle.Margin = MyThickness;
    SolidColorBrush MyBrush = new SolidColorBrush(Colors.Black);
    MyRectangle.Stroke = MyBrush;

    MyStroke = null;


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions