Share via


InkOverlay.Draw Method

Sets a rectangle in which to redraw the ink within the InkOverlay object.

Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in microsoft.ink.dll)

Syntax

'Declaration
Public Sub Draw ( _
    rDrawRect As Rectangle _
)
'Usage
Dim instance As InkOverlay
Dim rDrawRect As Rectangle

instance.Draw(rDrawRect)
public void Draw (
    Rectangle rDrawRect
)
public:
void Draw (
    Rectangle rDrawRect
)
public void Draw (
    Rectangle rDrawRect
)
public function Draw (
    rDrawRect : Rectangle
)
Not applicable.

Parameters

  • rDrawRect
    The rectangle in which to redraw the ink, in pixel coordinates.

Remarks

When the rDrawRect parameter is a null reference (Nothing in Visual Basic) (Nothing in Microsoft Visual Basic .NET), the entire window is redrawn.

A good use of this method is to redraw strokes that have been programmically changed. You can also call the Control.InvalidateControl.Invalidate method, but this causes a redrawing off all of the InkOverlay object's strokes. You can also call the Microsoft.Ink.Renderer.Draw method for this purpose, but the Renderer object is not able to draw any strokes as selected because it has no knowledge of which strokes are in the Selection collection.

Note

The AutoRedraw property must be set to true for the drawing to occur.

Example

This C# example is a method that changes the color of all the strokes in a Strokes collection that belong to the Ink object associated with an InkOverlay object, theInkOverlay. Changing the DrawingAttributes property of a Stroke object is not automatically and immediately visible. You can call the Invalidate or Refresh method on the control associated with theInkOverlay, but this causes a redrawing of all the Stroke objects in theInkOverlay. To achieve better performance, use the Draw method on the bounding box of the Strokes collection. Note that this means converting the bounding box from ink space coordinates to pixel coordinates.

private void ChangeColor(Strokes theStrokes, Color newColor)
{
    // Change the color of theStrokes
    foreach (Stroke stroke in theStrokes)
    {
        stroke.DrawingAttributes.Color = newColor;
    }

    // Convert bounding box to pixel coordinates
    Graphics g = CreateGraphics();
    Rectangle strokesBounds = theStrokes.GetBoundingBox();
    Point topLeft = strokesBounds.Location;
    Point bottomRight = strokesBounds.Location + strokesBounds.Size;
    theInkOverlay.Renderer.InkSpaceToPixel(g, ref topLeft);
    theInkOverlay.Renderer.InkSpaceToPixel(g, ref bottomRight);
    g.Dispose()
    strokesBounds = new Rectangle(topLeft, 
        new Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));

    // Redraw the strokes
    theInkOverlay.Draw(strokesBounds);
}

This Visual Basic .NET example is a method that changes the color of all the strokes in a Strokes collection belonging to the Ink object associated with an InkOverlay object, theInkOverlay. Changing the DrawingAttributes property of a Stroke object is not automatically and immediately visible. You can call the Invalidate or Refresh method on the control associated with theInkOverlay, but this causes a redrawing of all the Stroke objects in theInkOverlay. To achieve better performance, use the Draw method on the bounding box of the Strokes collection. Note that this means converting the bounding box from ink space coordinates to pixel coordinates.

Private Sub ChangeColor(ByVal theStrokes As Strokes, ByVal newColor As Color)
    ' Change the color of theStrokes
    Dim theStroke As Stroke
    For Each theStroke In theStrokes
        theStroke.DrawingAttributes.Color = newColor
    Next

    'Convert bounding box to pixel coordinates
    Dim g As Graphics = CreateGraphics()
    Dim strokesBounds As Rectangle = theStrokes.GetBoundingBox()
    Dim topLeft As Point = strokesBounds.Location
    Dim bottomRight As Point = New Point(strokesBounds.Right, strokesBounds.Bottom)
    theInkOverlay.Renderer.InkSpaceToPixel(g, topLeft)
    theInkOverlay.Renderer.InkSpaceToPixel(g, bottomRight)
    g.Dispose()
    strokesBounds = New Rectangle(topLeft, _
        New Size(bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y))

    'Redraw the strokes
    theInkOverlay.Draw(strokesBounds)

    End Sub

Platforms

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

InkOverlay Class
InkOverlay Members
Microsoft.Ink Namespace
Microsoft.Ink.Renderer.Draw