次の方法で共有


Renderer.Draw Method

Renderer.Draw Method

Draws the Strokes collection on the specified Graphics Leave Site surface.

Definition

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

Parameters

g System.Drawing.Graphics. The Graphics Leave Site object with which to draw.
strokes Microsoft.Ink.Strokes. The Strokes collection to draw.

Exceptions

ArgumentNullException Leave Site: The caller does not specify the Strokes collection.

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.

              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 the InkCollector's strokes
   theInkCollector.Renderer.Draw(e.Graphics, theInkCollector.Ink.Strokes);
}
            

[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.

              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 the InkCollector's strokes
    theInkCollector.Renderer.Draw(e.Graphics, theInkCollector.Ink.Strokes)
End Sub
            

See Also