DrawingVisual visual = new DrawingVisual(); using (DrawingContext dc = visual.RenderOpen()) { dc.DrawLine(new Pen(Brushes.Blue, 2), new Point(0, 0), new Point(50, 50)); }
DrawingVisual visual = new DrawingVisual(); using (DrawingContext dc = visual.RenderOpen()) { dc.DrawRectangle(Brushes.Red, new Pen(Brushes.Black, 2), new Rect(0, 0, 50, 50)); }
DrawingVisual visual = new DrawingVisual(); using (DrawingContext dc = visual.RenderOpen()) { FormattedText text = new FormattedText("Hello World", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 14, Brushes.Black); dc.DrawText(text, new Point(0, 0)); }This example creates a DrawingVisual object and opens a drawing context on it using the RenderOpen method. It then creates a FormattedText object with the text "Hello World" and draws it using the DrawText method of the drawing context object. The text is formatted to use the Arial font with a size of 14 and black color. Package library: PresentationCore