DrawingVisual.RenderOpen Yöntem

Tanım

DrawingVisual nesneyi işleme için açar. Döndürülen DrawingContext değer içinde DrawingVisualişlemek için kullanılabilir.

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

Döndürülenler

türünde DrawingContextbir değer.

Örnekler

Aşağıdaki örnekte, bir DrawingVisual nesnesi oluşturulur ve nesnesi DrawingContext döndürülür.

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

Çizim bağlamının içine çizdiğiniz sıra önemlidir. Başarılı olan her çizim diğerlerinin üzerine çizilir. Aşağıdaki örnekte, önce dikdörtgen, ardından metin çizilir.

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

Açıklamalar

yöntemini DrawingContextçağırdığınızdaClose, geçerli çizim içeriği için tanımlanan önceki çizim içeriğinin DrawingVisualyerini alır. Bu, yeni çizim içeriğini mevcut çizim içeriğine eklemenin hiçbir yolu olmadığı anlamına gelir.

Şunlara uygulanır

Ayrıca bkz.