WPF polygon rounded corners.

Rachel Adam 1 Reputation point
2021-02-09T14:49:31.327+00:00

I am drawing a simple pointer using the WPF polygon but I can't seem to get rounded corners on the five points using the following background code.

Polygon poly = new Polygon();

        poly.Points = new PointCollection();
        poly.Points.Add(new Point(0, 0));
        poly.Points.Add(new Point(12, 0));
        poly.Points.Add(new Point(17, 7));
        poly.Points.Add(new Point(12, 14));
        poly.Points.Add(new Point(0, 14));
        poly.StrokeLineJoin = PenLineJoin.Round;
        poly.StrokeStartLineCap = PenLineCap.Round;
        poly.StrokeEndLineCap = PenLineCap.Round;

It continually gives me sharp corners. Any help would be greatly appreciated.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,801 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DaisyTian-1203 11,626 Reputation points
    2021-02-10T02:45:13.543+00:00

    I updated your code like below:

    Polygon poly = new Polygon();  
                poly.Points = new PointCollection();  
                poly.Points.Add(new Point(0, 0));  
                poly.Points.Add(new Point(12, 0));  
                poly.Points.Add(new Point(17, 7));  
                poly.Points.Add(new Point(12, 14));  
                poly.Points.Add(new Point(0, 14));  
                poly.StrokeLineJoin = PenLineJoin.Round;  
                poly.StrokeStartLineCap = PenLineCap.Round;  
                poly.StrokeEndLineCap = PenLineCap.Round;  
      
                // Add below code  
                poly.StrokeThickness = 10;  
                poly.Stroke = Brushes.Red;  
      
                Thickness myThickness = new Thickness();  
                myThickness.Left = 50;  
                myThickness.Top = 50;  
                poly.Margin = myThickness;  
      
    

    The result picture is:
    66124-capture.png

    Is this want you want? If I misunderstand your question, please point out.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.