6

Click the points, I want to make from the polygon area on image.

myPolygon = new Polygon();
myPolygon.Stroke = Brushes.Black; 
myPolygon.Fill = Brushes.LightYellow; 
myPolygon.StrokeThickness = 2; 
myPolygon.HorizontalAlignment = HorizontalAlignment.Left; 
myPolygon.VerticalAlignment = VerticalAlignment.Center; 
myPolygon.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(Polygon_MouseDown); 
myPolygon.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(Polygon_MouseUp);     

private void Polygon_MouseDown(object sender, MouseButtonEventArgs e) 
{     
    Point p = e.GetPosition(image); 
    myPolygon.Points = new PointCollection() { new Point(p.X,p.Y) };
    RootCanvas.Children.Add(myPolygon); 
} //MouseClick Event BUT, did not click behavior.. I want draw a line along the points.

How can I do...?

DIF
  • 2,470
  • 6
  • 35
  • 49
user2853714
  • 71
  • 1
  • 1
  • 3

1 Answers1

12

We can draw Polygon using WPF canvas which is a collection of children objects.

Polygon p = new Polygon();
p.Stroke = Brushes.Black;
p.Fill = Brushes.LightBlue;
p.StrokeThickness = 1;
p.HorizontalAlignment = HorizontalAlignment.Left;
p.VerticalAlignment = VerticalAlignment.Center;
p.Points = new PointCollection() { new Point(10, 10), new Point(100, 100), new Point(200, 200) };
freeCanvas.Children.Add(p);

For more information,. please refer the following urls

http://www.codeproject.com/Articles/128705/WPF-rounded-corners-polygon

http://classicalprogrammer.wikidot.com/draw-dynamic-polygons-in-wpf

http://msdn.microsoft.com/en-us/library/ms747393.aspx

Sankar Ganesh PMP
  • 11,927
  • 11
  • 57
  • 90
  • SRY I lost my source.. myPolygon = new Polygon(); myPolygon.Stroke = Brushes.Black; myPolygon.Fill = Brushes.LightYellow; myPolygon.StrokeThickness = 2; myPolygon.HorizontalAlignment = HorizontalAlignment.Left; myPolygon.VerticalAlignment = VerticalAlignment.Center; myPolygon.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(Polygon_MouseDown); myPolygon.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(Polygon_MouseUp); //initialize – user2853714 Oct 07 '13 at 12:38
  • private void Polygon_MouseDown(object sender, MouseButtonEventArgs e) { Point p = e.GetPosition(image); myPolygon.Points = new PointCollection() { new Point(p.X,p.Y)}; RootCanvas.Children.Add(myPolygon); } //MouseClick Event BUT, did not click behavior.. I want draw a line along the points. – user2853714 Oct 07 '13 at 12:38