다음을 통해 공유


Ink.AddStrokesAtRectangle Method

Ink.AddStrokesAtRectangle Method

Specifies the known Strokes collection to insert into this Ink object at a specified rectangle.

Definition

Visual Basic .NET Public Sub AddStrokesAtRectangle( _
ByVal strokes As Strokes, _
ByVal destinationRectangle As Rectangle _
)
C# public void AddStrokesAtRectangle(
Strokes strokes,
Rectangle destinationRectangle
);
Managed C++ public: void AddStrokesAtRectangle(
Strokes *strokes,
Rectangle *destinationRectangle
);

Parameters

strokes Microsoft.Ink.Strokes. The Strokes collection to add to the Ink object.
destinationRectangle System.Drawing.Rectangle. The rectangle where the strokes are added, in ink space coordinates.

Exceptions

ArgumentException Leave Site: One of the parameters is not valid.
COMException Leave Site:
ObjectDisposedException Leave Site: The Ink object is disposed.

Remarks

A run-time error is thrown if the coordinates of the rectangle are {0,0,0,0}.

The source Strokes collection is appended to the InkEdit object.

When inserted, the strokes are scaled from the bounding box of the Strokes collection to the rectangle.

This method can be used to copy strokes within a single Ink object. The source strokes need not come from another Ink object.

Examples

[C#]

This C# example uses the AddStrokesAtRectangle method to take a copy of the ink from a main InkCollector object, panelMain, to a InkCollector object, panelThumb, while maintaining the proper scale and aspect ratio. To keep the thumbnail panel current, a Stroke event handler, panelMain_Stroke, is added to panelMain.

private void panelMain_Stroke(object sender, Microsoft.Ink.InkCollectorStrokeEventArgs e)
{
    // Create a bounding rectangle for panelThumb in ink space coordinates
    Point thePoint = Point.Empty;
    using (Graphics g = Graphics.FromHwnd(Handle))
    {
        thePoint = new Point(panelThumb.Width, panelThumb.Height);
        panelMain.Renderer.PixelToInkSpace(g, ref thePoint);
    }
    Rectangle theRectangle = new Rectangle(0, 0, thePoint.X, thePoint.Y);

    // Delete the old strokes in the thumbnail, and add the new strokes.
    panelThumb.Ink.DeleteStrokes();
    // The strokes are automatically scaled to the destination rectangle
    panelThumb.Ink.AddStrokesAtRectangle(panelMain.Ink.Strokes, theRectangle);
    Refresh();
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example uses the AddStrokesAtRectangle method to take a copy of the ink from a main InkCollector object, panelMain, to a InkCollector object, panelThumb, while maintaining the proper scale and aspect ratio. To keep the thumbnail panel current, a Stroke event handler, panelMain_Stroke, is added to panelMain.

Private Sub panelMain_Stroke(ByVal sender As System.Object, _
    ByVal e As Microsoft.Ink.InkCollectorStrokeEventArgs) Handles panelMain.Stroke

    'Create a bounding rectangle for panelThumb in ink space coordinates
    Dim g As Graphics = Graphics.FromHwnd(Handle)
    Dim thePoint As Point = New Point(panelThumb.Width, panelThumb.Height)
    panelMain.Renderer.PixelToInkSpace(g, thePoint)
    'Dispose of the Graphics object
    g.Dispose()
    Dim theRectangle As Rectangle = New Rectangle(0, 0, thePoint.X, thePoint.Y)

    'Delete the old strokes in the thumbnail, and add the new strokes.
    panelThumb.Ink.DeleteStrokes()
    'The strokes are automatically scaled to the destination rectangle
    panelThumb.Ink.AddStrokesAtRectangle(panelMain.Ink.Strokes, theRectangle)
    Refresh()
End Sub

See Also