DrawingVisual.RenderOpen メソッド

定義

レンダリング対象の DrawingVisual オブジェクトを開きます。Opens the DrawingVisual object for rendering. 返された DrawingContext 値は DrawingVisual にレンダリングするために使用できます。The returned DrawingContext value can be used to render into the DrawingVisual.

public:
 System::Windows::Media::DrawingContext ^ RenderOpen();
public System.Windows.Media.DrawingContext RenderOpen ();
member this.RenderOpen : unit -> System.Windows.Media.DrawingContext
Public Function RenderOpen () As DrawingContext

戻り値

DrawingContext 型の値。A value of type DrawingContext.

次の例DrawingVisualでは、オブジェクトが作成され、 DrawingContextそのオブジェクトが返されます。In the following example, a DrawingVisual object is created, and its DrawingContext returned.

// 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

描画コンテキストに描画する順序は重要です。その後の描画は、それぞれの図形の上に描画されます。The order in which you draw into the drawing context is important - each succeeding drawing is drawn on top of the others. 次の例では、最初に四角形が描画され、次にテキストが描画されます。In the following example, the rectangle is drawn first, then the text.

// Retrieve the DrawingContext in order to draw into the visual object.
DrawingContext drawingContext = drawingVisual.RenderOpen();

// Draw a rectangle into the DrawingContext.
Rect rect = new Rect(new Point(160, 100), new Size(320, 80));
drawingContext.DrawRectangle(Brushes.LightBlue, (Pen)null, rect);

// Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(
   new FormattedText("Hello, world",
      CultureInfo.GetCultureInfo("en-us"),
      FlowDirection.LeftToRight,
      new Typeface("Verdana"),
      36, Brushes.Black),
      new Point(200, 116));

// Persist the drawing content.
drawingContext.Close();
' Retrieve the DrawingContext in order to draw into the visual object.
Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()

' Draw a rectangle into the DrawingContext.
Dim rect As New Rect(New Point(160, 100), New Size(320, 80))
drawingContext.DrawRectangle(Brushes.LightBlue, CType(Nothing, Pen), rect)

' Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(New FormattedText("Hello, world", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 36, Brushes.Black), New Point(200, 116))

' Persist the drawing content.
drawingContext.Close()

注釈

のメソッドをClose呼び出すと、現在の描画コンテンツは、 DrawingVisualに対して定義されている前の描画コンテンツを置き換えます。 DrawingContextWhen you call the Close method of the DrawingContext, the current drawing content replaces any previous drawing content defined for the DrawingVisual. これは、既存の描画コンテンツに新しい描画コンテンツを追加する方法がないことを意味します。This means that there is no way to append new drawing content to existing drawing content.

適用対象

こちらもご覧ください