Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Drawing Polygon on UserControl

 
 
Old 05-03-2007   #1 (permalink)
Sudha


 
 

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 SpecsSystem Spec
Old 02-21-2008   #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 SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46