Bagikan melalui


Renderer.Draw Method (IntPtr, Stroke)

Draws the Stroke object on the device context whose handle is passed in.

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

Syntax

'Declaration
Public Sub Draw ( _
    hdc As IntPtr, _
    stroke As Stroke _
)
'Usage
Dim instance As Renderer 
Dim hdc As IntPtr 
Dim stroke As Stroke

instance.Draw(hdc, stroke)
public void Draw(
    IntPtr hdc,
    Stroke stroke
)
public:
void Draw(
    IntPtr hdc, 
    Stroke^ stroke
)
public function Draw(
    hdc : IntPtr, 
    stroke : Stroke
)

Parameters

  • hdc
    Type: System.IntPtr

    The handle of the device context on which to draw.

Remarks

Note

Use the appropriate overload that accepts a Graphics object instead of the one that accepts an IntPtr whenever possible.

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.

Security noteSecurity Note:

If using under partial trust, this method requires SecurityPermissionFlag.UnmanagedCode permission in addition to the permissions required by InkCollector. For more information about security issues and partial trust, see Security and Trust.

Examples

In this example, a Stroke object is created in an Ink object. The stroke is in the shape of the English letter N. Once created, the stroke is displayed on the Panel associated with the InkOverlay object as well as on another panel. This is acomplished by calling the Draw method twice, passing different device context handle values to the hdc parameter.

Using g1 As Graphics = mInkOverlay.AttachedControl.CreateGraphics()
    ' create the stroke 
    Dim strokePoints() As Point = _
           { _
               New Point(200, 4000), _
               New Point(200, 200), _
               New Point(3000, 4000), _
               New Point(3000, 200) _
           }
    Dim oneStroke As Stroke = mInkOverlay.Ink.CreateStroke(strokePoints)
    ' draw the stroke on the control attached to InkOverlay 
    ' get the handle to the device context 
    Dim hdc1 As IntPtr = g1.GetHdc()
    ' draw the stroke
    mInkOverlay.Renderer.Draw(hdc1, oneStroke)
    ' release the handle to the device context
    g1.ReleaseHdc(hdc1)
    ' now draw the stroke on another control also 
    Using g2 As Graphics = Me.panelForDraw.CreateGraphics()
        ' get the handle to the device context 
        Dim hdc2 As IntPtr = g2.GetHdc()
        ' draw the stroke
        mInkOverlay.Renderer.Draw(hdc2, oneStroke)
        ' release the handle to the device context
        g2.ReleaseHdc(hdc1)
    End Using 
End Using
using (Graphics g1 = mInkOverlay.AttachedControl.CreateGraphics())
{
    // create the stroke
    Point[] strokePoints = new Point[4] 
        { 
            new Point(200,  4000), 
            new Point(200, 200),
            new Point(3000, 4000),
            new Point(3000, 200)
        };

    Stroke oneStroke = mInkOverlay.Ink.CreateStroke(strokePoints);
    // draw the stroke on the control attached to InkOverlay 
    // get the handle to the device context
    IntPtr hdc1 = g1.GetHdc();
    // draw the stroke
    mInkOverlay.Renderer.Draw(hdc1, oneStroke);
    // release the handle to the device context
    g1.ReleaseHdc(hdc1);
    // now draw the stroke on another control also 
    using (Graphics g2 = this.panelForDraw.CreateGraphics())
    {
        // get the handle to the device context
        IntPtr hdc2 = g2.GetHdc();
        // draw the stroke
        mInkOverlay.Renderer.Draw(hdc2, oneStroke);
        // release the handle to the device context
        g2.ReleaseHdc(hdc1);
    }
}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

Renderer Class

Renderer Members

Draw Overload

Microsoft.Ink Namespace

Renderer.SetViewTransform

DrawingAttributes

Strokes

Stroke