DrawingVisual.RenderOpen 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
開啟用於呈現的 DrawingVisual 物件。 傳回的 DrawingContext 值可用來在 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 的值。
範例
在下列範例中,會 DrawingVisual 建立 物件,並傳回物件 DrawingContext 。
// 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
您繪製到繪圖內容的順序很重要- 每個成功的繪圖都會繪製到其他繪圖之上。 在下列範例中,會先繪製矩形,然後繪製文字。
// 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 的 DrawingContext 方法時,目前的繪圖內容會取代為 DrawingVisual 定義的任何先前繪圖內容。 這表示無法將新的繪圖內容附加至現有的繪圖內容。