![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Drawing Polygon on UserControl Hello Everybody, I am writing WPF UserControl using C#. This UserControl will draw image and do some animations. Now for drawing images, i am getting image from other source as XAML data. This XAML data contains full of PolyLines,Polygons and Ellipses. I wanted to draw each of this element on UserControl's DrawingContext by overriding OnRender(). Correct me if there is any better way. I think i can draw PolyLines and Ellipse using PathGeomentry. But how to draw Polygon on DrawingContext? Or is there anyother better way of doing? I appreciate your help. Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| Windows XP | Re: Drawing Polygon on UserControl You have to use the DrawGeometry() function. Have a look at: PathFigure Class (System.Windows.Media) Below is the function I created in my program. Don't ask about the performance of this code though, probably not very good. Code: private void renderPolygon(DrawingContext dc, List<Point> points, Brush fillColor, Pen outline)
{
if (points.Count > 1)
{
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = points[0];
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
for (int i = 1; i < points.Count; i++)
myPathSegmentCollection.Add(new LineSegment(points[i], true));
myPathFigure.Segments = myPathSegmentCollection;
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures.Add(myPathFigure);
dc.DrawGeometry(fillColor, outline, myPathGeometry);
}
}
|
My System Specs![]() |
| Thread Tools | |
| |