Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Stroke.GetBounds Method

Retrieves the bounding box for the Stroke object.

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

'Declaration
Public Function GetBounds As Rect

Return Value

Type: System.Windows.Rect
A Rect structure defining the bounding box for the Stroke object.

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 Stroke object.

Run this sample


    Private MyStroke As Stroke

    Public Sub New()
        MyBase.New()
        InitializeComponent()
        SetBoundary()
    End Sub

    'A new stroke object, MyStroke, is created and is added to the StrokeCollection object
    'of the InkPresenter, MyIP
    Private Sub MyIP_MouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseEventArgs)
        MyIP.CaptureMouse()
        Dim MyStylusPointCollection As StylusPointCollection = New StylusPointCollection
        MyStylusPointCollection.Add(e.StylusDevice.GetStylusPoints(MyIP))
        MyStroke = New Stroke(MyStylusPointCollection)
        MyIP.Strokes.Add(MyStroke)
    End Sub

    'StylusPoint objects are collected from the MouseEventArgs and added to MyStroke
    Private Sub MyIP_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        If (Not (MyStroke) Is Nothing) Then
            MyStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(MyIP))
        End If
    End Sub

    'GetBounds() method is used to draw a rectangular boundary on every stroke 
    'as soon as the stroke is completed.
    Private Sub MyIP_LostMouseCapture(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim MyRect As Rect = New Rect
        MyRect = MyStroke.GetBounds
        Dim MyRectangle As Rectangle = New Rectangle
        MyRectangle.Height = MyRect.Height
        MyRectangle.Width = MyRect.Width
        Dim MyThickness As Thickness = New Thickness(MyRect.X, MyRect.Top, 0, 0)
        MyRectangle.Margin = MyThickness
        Dim MyBrush As SolidColorBrush = New SolidColorBrush(Colors.Black)
        MyRectangle.Stroke = MyBrush
        MyIP.Children.Add(MyRectangle)
        MyStroke = Nothing
    End Sub



Silverlight

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

ADD
Show:
© 2015 Microsoft