共用方式為


DrawingVisual 建構函式

定義

初始化 DrawingVisual 類別的新執行個體。

public:
 DrawingVisual();
public DrawingVisual ();
Public Sub New ()

範例

在下列範例中, DrawingVisual 會建立 物件,並將矩形繪製到其繪圖內容中。 請注意,您必須呼叫 CloseDrawingContext 方法來保存繪圖內容。

// Create a DrawingVisual that contains a rectangle.
private DrawingVisual CreateDrawingVisualRectangle()
{
    DrawingVisual drawingVisual = new DrawingVisual();

    // Retrieve the DrawingContext in order to create new drawing content.
    DrawingContext drawingContext = drawingVisual.RenderOpen();

    // Create a rectangle and draw it in the DrawingContext.
    Rect rect = new Rect(new System.Windows.Point(160, 100), new System.Windows.Size(320, 80));
    drawingContext.DrawRectangle(System.Windows.Media.Brushes.LightBlue, (System.Windows.Media.Pen)null, rect);

    // Persist the drawing content.
    drawingContext.Close();

    return drawingVisual;
}
' Create a DrawingVisual that contains a rectangle.
Private Function CreateDrawingVisualRectangle() As DrawingVisual
    Dim drawingVisual As New DrawingVisual()

    ' Retrieve the DrawingContext in order to create new drawing content.
    Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

    ' Create a rectangle and draw it in the DrawingContext.
    Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
    drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

    ' Persist the drawing content.
    drawingContext.Close()

    Return drawingVisual
End Function

備註

當您建立 DrawingVisual 物件時,它沒有繪圖內容。 您可以藉由擷取物件的繪圖內容並繪製到其中,來新增文字、圖形或影像內容。 呼叫 物件的 方法 DrawingVisual 會傳 RenderOpen 回繪圖內容。

適用於