1 使用预定义形状

     画笔属性pen.StartCap和pen.EndCap指定线条的两端形状。

     预定义的形状:LineCap.Round 、LineCap.ArrowAnchor等等

      如:     pen.StartCap = LineCap.Round;

2 使用自定义形状

     如果使用自定义的端部形状,则使用pen.CustomStartCap和pen.CustomEndCap属性

      CustomLineCap  myCap = new CustomLineCap(null,path);//自定义端部形状

     path为GraphicsPath类型。

     如:pen.CustomStartCap = mycap;

 

示例:

 

 GraphicsPath();

            // Create the outline for our custom end cap.
            hPath.AddLine(new Point(00), new Point(05));
            hPath.AddLine(
new Point(05), new Point(51));
            hPath.AddLine(
new Point(51), new Point(31));

            
//构造一个挂钩形状的端部形状
            CustomLineCap HookCap = new CustomLineCap(null, hPath);

            
// 设定画笔线条端部形状为它
            Pen customCapPen = new Pen(Color.Black, 5);
            customCapPen.CustomStartCap 
= HookCap;
            customCapPen.CustomEndCap 
= HookCap;
            
            
//使用预定义的端部形状
            Pen capPen = new Pen(Color.Red, 10);
            capPen.StartCap 
= LineCap.Round;
            capPen.EndCap 
= LineCap.ArrowAnchor;
          
            
//无端部形状
            Pen pen = new Pen(Color.Chartreuse, 7);
            
// Create a line to draw.
            Point[] points = { new Point(100100), new Point(300100) };
        
            
// Draw the lines.
            e.Graphics.DrawLines(capPen, points);

            e.Graphics.DrawLines(pen,points);
            e.Graphics.DrawLines(customCapPen, points);

相关文章:

  • 2021-08-30
  • 2021-11-28
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-03-03
  • 2021-05-16
相关资源
相似解决方案