Export (0) Print
Expand All

Shape Class

Provides a base class for shape elements, such as Ellipse, Polygon, and Rectangle.

Namespace:  System.Windows.Shapes
Assembly:  PresentationFramework (in PresentationFramework.dll)

[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
public abstract class Shape : FrameworkElement

This example shows you how to draw lines by using the Line element.

To draw a line, create a Line element. Use its X1 and Y1 properties to set its start point; and use its X2 and Y2 properties to set its end point. Finally, set its Stroke and StrokeThickness because a line without a stroke is invisible.

Setting the Fill element for a line has no effect, because a line has no interior.

The following example draws three lines inside a Canvas element.

<Canvas Height="300" Width="300">

  <!-- Draws a diagonal line from (10,10) to (50,50). -->
    X1="10" Y1="10"
    X2="50" Y2="50"
    StrokeThickness="4" />

       and moves it 100 pixels to the right. -->
    X1="10" Y1="10"
    X2="50" Y2="50"

  <!-- Draws a horizontal line from (10,60) to (150,60). -->
     X1="10" Y1="60"
     X2="150" Y2="60"



More Code

How to: Draw an Ellipse or a Circle This example shows how to draw ellipses and circles by using the Ellipse element. To draw an ellipse, create an Ellipse element and specify its Width and Height. Use its Fill property to specify the Brush that is used to paint the interior of the ellipse. Use its Stroke property to specify the Brush that is used to paint the outline of the ellipse. The StrokeThickness property specifies the thickness of the ellipse outline.
How to: Draw a Closed Shape by Using the Polygon Element This example shows how to draw a closed shape by using the Polygon element. To draw a closed shape, create a Polygon element and use its Points property to specify the vertices of a shape. A line is automatically drawn that connects the first and last points. Finally, specify a Fill, a Stroke, or both.
How to: Draw a Polyline by Using the Polyline Element This example shows how to draw a polyline, which is a series of connected lines, by using the Polyline element.





.NET Framework

Supported in: 3.5, 3.0

Community Additions

© 2015 Microsoft