DrawingVisual.RenderOpen Method

Opens the DrawingVisual object for rendering. The returned DrawingContext value can be used to render into the DrawingVisual.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

'Declaration
Public Function RenderOpen As DrawingContext

Return Value

Type: System.Windows.Media.DrawingContext
A value of type DrawingContext.

When 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.

In the following example, a DrawingVisual object is created, and its DrawingContext returned.


		' 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.
			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()


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft