Condividi tramite


Metodo Renderer.Draw (IntPtr, Stroke, DrawingAttributes)

Aggiornamento: novembre 2007

Disegna l'oggetto Stroke, con la proprietà DrawingAttributes, sul contesto di dispositivo il cui handle viene passato.

Spazio dei nomi:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Sintassi

'Dichiarazione
<UIPermissionAttribute(SecurityAction.Demand, Window := UIPermissionWindow.SafeTopLevelWindows)> _
<SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode := True)> _
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public Sub Draw ( _
    hdc As IntPtr, _
    stroke As Stroke, _
    da As DrawingAttributes _
)
'Utilizzo
Dim instance As Renderer
Dim hdc As IntPtr
Dim stroke As Stroke
Dim da As DrawingAttributes

instance.Draw(hdc, stroke, da)
[UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.SafeTopLevelWindows)]
[SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public void Draw(
    IntPtr hdc,
    Stroke stroke,
    DrawingAttributes da
)
[UIPermissionAttribute(SecurityAction::Demand, Window = UIPermissionWindow::SafeTopLevelWindows)]
[SecurityPermissionAttribute(SecurityAction::Demand, UnmanagedCode = true)]
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
public:
void Draw(
    IntPtr hdc, 
    Stroke^ stroke, 
    DrawingAttributes^ da
)
/** @attribute UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.SafeTopLevelWindows) */
/** @attribute SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = true) */
/** @attribute PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust") */
public void Draw(
    IntPtr hdc,
    Stroke stroke,
    DrawingAttributes da
)
public function Draw(
    hdc : IntPtr, 
    stroke : Stroke, 
    da : DrawingAttributes
)

Parametri

  • hdc
    Tipo: System.IntPtr
    Handle del contesto di dispositivo su cui disegnare.

Note

Nota

Utilizzare l'overload appropriato che accetta un oggetto Graphics anziché quello che accetta un oggetto IntPtr, quando possibile.

Lo spessore di penna viene regolato in modo appropriato, in base alla modalità di utilizzo del metodo SetViewTransform. In particolare, lo spessore della penna viene moltiplicato (o ridimensionato) per la radice quadrata del determinante della trasformazione della visualizzazione.

Nota

Se lo spessore della penna non viene impostato in modo esplicito, il valore predefinito è 53. È necessario moltiplicare lo spessore della penna per la radice quadrata del determinante per produrre il riquadro corretto. L'altezza e la larghezza del riquadro sono espanse della metà di questa quantità in ogni direzione.

Ad esempio, si consideri che lo spessore della penna sia 53, la radice quadrata del determinante sia 50 e il riquadro sia (0, 0, 1000, 1000). La regolazione dello spessore della penna nel riquadro in ogni direzione viene calcolata come (53 * 50)/2 e i lati destro e inferiore vengono incrementati di uno. Il risultato è un riquadro di cui è stato eseguito il rendering di (-1325,-1325,2326,2326).

L'oggetto Renderer impone l'impostazione delle origini del riquadro di visualizzazione e della finestra su 0,0. Qualsiasi impostazione esistente viene salvata e ripristinata, ma non viene utilizzata da Renderer. Per lo scorrimento, utilizzare i metodi GetViewTransform e GetObjectTransform dell'oggetto Renderer.

ms569822.alert_security(it-it,VS.90).gifNota sulla sicurezza:

Se utilizzato in attendibilità parziale, questo metodo richiede l'autorizzazione SecurityPermissionFlag.UnmanagedCode, oltre alle autorizzazioni richieste da InkCollector. Per ulteriori informazioni sui problemi di sicurezza e sull'attendibilità parziale, vedere Security and Trust.

Esempi

In questo esempio l'intero insieme Strokes di un oggetto Ink associato a un oggetto InkOverlay viene visualizzato in un Panel diverso da quello associato all'oggetto InkOverlay stesso.

Inoltre, quando si visualizzano gli oggetti Stroke sul pannello alternativo, viene utilizzato un oggetto DrawingAttributes modificato. Vengono applicate delle modifiche tali da invertire il colore del tratto e raddoppiarne lo spessore. L'oggetto DrawingAttributes modificato viene quindi passato al metodo Draw tramite il parametro da. Tali operazioni non influiscono sulla proprietà DrawingAttributes dei tratti originali.

' Access to the Ink.Strokes property returns a copy of the Strokes object.
' This copy must be implicitly (via using statement) or explicitly
' disposed of in order to avoid a memory leak.
Using allStrokes As Strokes = mInkOverlay.Ink.Strokes
    ' get a graphics object for another panel
    Using g As Graphics = Me.panelForDraw.CreateGraphics()
        ' get a Renderer object. We could have used
        ' mInkOverlay.Renderer, this is another way
        Dim R As Renderer = New Renderer()
        ' get the handle to the device context
        Dim hdc As IntPtr = g.GetHdc()
        ' traverse the stroke collection
        For Each oneStroke As Stroke In allStrokes
            Dim da As DrawingAttributes = oneStroke.DrawingAttributes.Clone()
            ' invert the stroke color
            Dim cR As Byte = Not da.Color.R
            Dim cG As Byte = Not da.Color.G
            Dim cB As Byte = Not da.Color.B
            da.Color = Color.FromArgb(da.Color.A, cR, cG, cB)
            ' double the stroke width
            da.Width *= 2
            ' draw the stroke
            R.Draw(hdc, oneStroke, da)
        Next
        ' release the handle to the device context
        g.ReleaseHdc(hdc)
    End Using
End Using
// Access to the Ink.Strokes property returns a copy of the Strokes object.
// This copy must be implicitly (via using statement) or explicitly
// disposed of in order to avoid a memory leak.
using (Strokes allStrokes = mInkOverlay.Ink.Strokes)
{
    // get a graphics object for another panel
    using (Graphics g = this.panelForDraw.CreateGraphics())
    {
        // get a Renderer object. We could have used
        // mInkOverlay.Renderer, this is another way
        Renderer R = new Renderer();
        // get the handle to the device context
        IntPtr hdc = g.GetHdc();
        // traverse the stroke collection
        foreach (Stroke oneStroke in allStrokes)
        {
            DrawingAttributes da = oneStroke.DrawingAttributes.Clone();
            // invert the stroke color
            byte cR = (byte)~(da.Color.R);
            byte cG = (byte)~(da.Color.G);
            byte cB = (byte)~(da.Color.B);
            da.Color = Color.FromArgb(da.Color.A, cR, cG, cB);
            // double the stroke width
            da.Width *= 2;
            // draw the stroke
            R.Draw(hdc, oneStroke, da);
        }
        // release the handle to the device context
        g.ReleaseHdc(hdc);
    }
}

Piattaforme

Windows Vista

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.0

Vedere anche

Riferimenti

Renderer Classe

Membri Renderer

Overload Draw

Spazio dei nomi Microsoft.Ink

Renderer.SetViewTransform

DrawingAttributes

Strokes

Stroke