Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Phone

Vector Graphics : Polygon and Fill

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3/24/2011 3:45:17 PM
The Polyline that I’ve been using to demonstrate dotted lines is only three sides of a square:
<Grid Background="LightCyan">
<Polyline Points="100 100, 380 100,
380 380, 100 380"
Stroke="Red"
StrokeThickness="20"
StrokeStartLineCap="Round"
StrokeEndLineCap="Round"
StrokeLineJoin="Round"
StrokeDashArray="0 2"
StrokeDashCap="Round" />
</Grid>



But if you set the Fill brush, the interior is filled as if the polyline describes a closed area:

<Grid Background="LightCyan">
<Polyline Points="100 100, 380 100,
380 380, 100 380"
Stroke="Red"
StrokeThickness="20"
Fill="Blue"
StrokeStartLineCap="Round"
StrokeEndLineCap="Round"
StrokeLineJoin="Round"
StrokeDashArray="0 2"
StrokeDashCap="Round" />
</Grid>



If you want the figure to be really closed, you can add another point to the Points collection that is the same as the first point, or you can use a Polygon rather than a Polyline:

<Grid Background="LightCyan">
<Polygon Points="100 100, 380 100,
380 380, 100 380"
Stroke="Red"
StrokeThickness="20"
Fill="Blue"
StrokeStartLineCap="Round"
StrokeEndLineCap="Round"
StrokeLineJoin="Round"
StrokeDashArray="0 2"
StrokeDashCap="Round" />
</Grid>



Both elements have the same Points collection, but the Polygon is closed automatically if necessary.

Once you start filling enclosed area with Polygon, a question comes up about how the interior should be handled when boundary lines overlap. The Polygon class defines a property named FillRule that gives you a choice. The classic example is the five-pointed star. Here’s the default FillRule, called EvenOdd:

<Grid Background="LightCyan">
<Polygon Points="240 48, 352 396,
58 180, 422 180,
128 396"
Stroke="Red"
StrokeThickness="10"
Fill="Blue"
FillRule="EvenOdd" />
</Grid>



The EvenOdd algorithm determines if an enclosed area should be filled or not by conceptually taking a point in that area, for example, somewhere in the center, and drawing an imaginary line out to infinity. That imaginary line will cross some boundary lines. If it crosses an odd number of boundary lines, such as happens in the five points, then the area is filled. For an even number, like the center, the area is not filled.

The alternative is a FillRule called NonZero:

<Grid Background="LightCyan">
<Polygon Points="240 48, 352 396,
58 180, 422 180,
128 396"
Stroke="Red"
StrokeThickness="10"
Fill="Blue"
FillRule="NonZero" />
</Grid>



The NonZero fill rule is a bit more complex because it takes account of the directions that boundary lines are drawn. If the boundary lines drawn in one direction balance out the boundary lines drawn in the opposite direction, then the area is not filled. In any interior area of this star, however, all the boundary lines go in the same direction.

Neither of these two FillRule options guarantees that all interior areas get filled. Here’s a rather artificial figure that has an enclosed but unfilled area even with NonZero:

<Grid Background="LightCyan">
<Polygon Points=" 80 160, 80 320,
240 320, 240 80,
400 80, 400 240,
160 240, 160 400,
320 400, 320 160"
Stroke="Red"
StrokeThickness="10"
Fill="Blue"
FillRule="NonZero" />
</Grid>


Other -----------------
- Vector Graphics : Caps, Joins, and Dashes
- Vector Graphics : Polylines and Custom Curves
- Vector Graphics : Overlapping and ZIndex
- Vector Graphics : Canvas and Grid
- Vector Graphics : The Shapes Library
- Data Bindings : TextBox Binding Updates
- Data Bindings : Give and Take
- Data Bindings : Converters with Properties
- Data Bindings : Simple Decision Making
- Data Bindings : Setting the DataContext
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server