Renderer.Draw Method

Renderer.Draw Method

Draws the Stroke object, with DrawingAttributes, on the specified Graphics Leave Site surface.

Definition

Visual Basic .NET Public Sub Draw( _
ByVal g As Graphics, _
ByVal stroke As Stroke, _
ByVal da As DrawingAttributes _
)
C# public void Draw(
Graphics g,
Stroke stroke,
DrawingAttributes da
);
Managed C++ public: void Draw(
Graphics *g,
Stroke *stroke,
DrawingAttributes *da
);

Parameters

g System.Drawing.Graphics. The Graphics Leave Site object with which to draw.
stroke Microsoft.Ink.Stroke. The Stroke object to draw.
da Microsoft.Ink.DrawingAttributes. The DrawingAttributes property to use for the drawing. If drawing attributes are specified, they override the drawing attributes on the Stroke object.

Exceptions

ArgumentNullException Leave Site: The caller does not specify the Stroke object.

Remarks

Important Security InformationSecurity Alert: For managed code, use the appropriate overload that accepts a Graphics Leave Site object instead of the one that accepts an IntPtr Leave Site; otherwise, you need to hold on to the handle in such a way that results in a memory leak. The overloads that accept an hdc parameter are useful if you are using resources that are unmanaged code.

The pen width is adjusted appropriately, based on how you use SetViewTransform method. Specifically, the pen width is multiplied (or scaled) by the square root of the determinant of the view transform.

Note: If you have not set the pen width explicitly, it is 53 by default. You must multiply the pen width by the square root of the determinant to yield the correct bounding box. The height and width of the bounding box are expanded by half this amount in each direction.

For example, consider that the pen width is 53, the square root of the determinant is 50, and the bounding box is (0,0,1000,1000). The pen width adjustment to the bounding box in each direction is calculated as (53*50)/2, and the right and bottom sides are incremented by one. This results in a rendered bounding box of (-1325,-1325,2326,2326).

The Renderer object forces the viewport and window origins to 0,0. Any existing settings are saved and restored, but are not used by the Renderer. To perform scrolling, use the Renderer object's GetViewTransform and GetObjectTransform methods.

Examples

[C#]

This C# example takes the Strokes collection from an Ink object associated with an InkCollector object, theInkCollector, which is attached to a Panel Leave Site, panelForInking. The example then calls the Draw method to draw the strokes onto a Graphics Leave Site object attached to another Panel Leave Site, panelForDrawing. New Stroke objects with a height or width less than than or equal to 300 HIMETRIC units receive a DrawingAttributes property that renders them red.

              using Microsoft.Ink;
...
// Members
private InkCollector theInkCollector;
private System.Windows.Forms.Panel panelForInking;
private System.Windows.Forms.Panel panelForDrawing;
...
// In the constructor...
    // Initialize InkCollector
    theInkCollector = new InkCollector(panelForInking.Handle);
    theInkCollector.Enabled = true;
    theInkCollector.Stroke += new InkCollectorStrokeEventHandler(theInkCollector_Stroke);

    // Paint event handler for drawing panel
    panelForDrawing.Paint += new PaintEventHandler(panelForDrawing_Paint);
...

private void theInkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
{
    // Force a repaint on the drawing panel
    panelForDrawing.Refresh();
}

private void panelForDrawing_Paint(object sender, PaintEventArgs e)
{
    // Draw all strokes, but mark small ones in red
    foreach (Stroke stroke in theInkCollector.Ink.Strokes)
    {
        Rectangle strokeBounds = stroke.GetBoundingBox();
        if (strokeBounds.Width > 300 ||
            strokeBounds.Height > 300)
        {
            theInkCollector.Renderer.Draw(e.Graphics, stroke);
        }
        else
        {
            DrawingAttributes redAttributes = stroke.DrawingAttributes.Clone();
            redAttributes.Color = Color.Red;
            theInkCollector.Renderer.Draw(e.Graphics, stroke, redAttributes);
        }
    }
}
            

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example takes the Strokes collection from an Ink object associated with an InkCollector object, theInkCollector, which is attached to a Panel Leave Site, panelForInking. The example then calls the Draw method to draw the strokes onto a Graphics Leave Site object attached to another Panel Leave Site, panelForDrawing. New Stroke objects with a height or width less than than or equal to 300 HIMETRIC units receive a DrawingAttributes property that renders them red.

              Imports Microsoft.Ink
...
    'Initialize InkCollector in the Form's New subroutine
    theInkCollector = New InkCollector(PanelForInking.Handle)
    theInkCollector.Enabled = True
...
Friend WithEvents theInkCollector As InkCollector
Friend WithEvents PanelForInking As System.Windows.Forms.Panel
Friend WithEvents PanelForDrawing As System.Windows.Forms.Panel
...
Private Sub theInkCollector_Stroke(ByVal sender As Object, ByVal e As Microsoft.Ink.InkCollectorStrokeEventArgs) _
Handles theInkCollector.Stroke
    'Force a repaint on the PanelForDrawing
    PanelForDrawing.Refresh()
End Sub

Private Sub PanelForDrawing_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles PanelForDrawing.Paint
    'Draw all strokes, but mark small ones in red
    Dim theStroke As Stroke
    For Each theStroke In theInkCollector.Ink.Strokes
        Dim strokeBounds As Rectangle = theStroke.GetBoundingBox()
        If strokeBounds.Width > 300 Or strokeBounds.Height > 300 Then
            theInkCollector.Renderer.Draw(e.Graphics, theStroke)
        Else
            Dim redAttributes As DrawingAttributes = theStroke.DrawingAttributes.Clone()
            redAttributes.Color = Color.Red
            theInkCollector.Renderer.Draw(e.Graphics, theStroke, redAttributes)
        End If
    Next
End Sub
            

See Also