簡體   English   中英

如何繪制多邊形?(在C#WPF項目中)

[英]How do I draw polygon?( in C# WPF project)

點擊我想從圖像上的多邊形區域制作的點。

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.

我能怎么做...?

我們可以使用WPF畫布繪制Polygon,WPF畫布是子對象的集合。

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);

欲獲得更多信息,。 請參考以下網址

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM