代码之家  ›  专栏  ›  技术社区  ›  serhio

来自.NET的CustomLineCap构造函数的NotImplementedException

  •  2
  • serhio  · 技术社区  · 14 年前

    我想画一个自定义的线帽-一个半径为r的等边三角形。显然我不能:

      Dim triangleSide As Single = CSng(3 * r / Math.Sqrt(3))
      Dim triangleHeight As Single = CSng(3 * r / 2)
      path = New GraphicsPath()
      Dim points() As PointF = New PointF() { _ 
          New PointF(-triangleSide / 2, 0), _ 
          New PointF(triangleSide / 2, 0), _
          New PointF(0, triangleHeight) }
      path.AddLines(points)
    
      ' Not Implemented Exception, Was is Das? '
      _HlpCap = New CustomLineCap(path, Nothing) 
    

    编辑:

    马克说了这句话后,我试着用 (Nothing, path)

    2 回复  |  直到 14 年前
        1
  •  0
  •   Mark Cidade    14 年前

    GDI+库返回 NotImplemented GdipCreateCustomLineCap() 功能。尝试通过笔划路径,而不是 Nothing :

      Dim path2 As GraphicsPath = New GraphicsPath()
      path2.AddLines(points);
      _HlpCap = New CustomLineCap(path, path2) 
    
        2
  •  0
  •   Ruud    13 年前

    显然,路径不能穿过x轴。我使用以下代码创建箭头帽:

      GraphicsPath capPath = new GraphicsPath();
      float arrowSize = 2.0f;
      capPath.AddLines(new PointF[] {
        new PointF(arrowSize, -(float)Math.Sqrt(3.0) * arrowSize),
        new PointF(0.0f, -0.01f),
        new PointF(-arrowSize, -(float)Math.Sqrt(3.0) * arrowSize)
      });
    
      CustomLineCap arrowCap = new CustomLineCap(capPath, null, LineCap.NoAnchor, (float)Math.Sqrt(3.0) * arrowSize);
    
        3
  •  0
  •   Wyck    4 年前

    坏的

    GraphicsPath 试图在线的末端画一个箭头并导致 System.NotImplementedException

    GraphicsPath capPath = new GraphicsPath();
    capPath.AddLine(0, 8, -5, 0);
    capPath.AddLine(-5, 0, 5, 0);
    arrowPen.CustomEndCap = new CustomLineCap(capPath, null); // System.NotImplementedException
    

    这个 remarks in the docs

    这个 fillPath strokePath 将被忽略。如果 null , 填充路径

    这是措辞拙劣的情况之一。医生说 应该 “拦截”否则你会被逮捕 System.NotImplementedException异常 . 此拦截问题仅适用于 填充路径 ,而不是 . (文档可能也会用到一些图片。)

    很好

    下面是一个

    enter image description here

    GraphicsPath capPath = new GraphicsPath();
    capPath.AddLine(0, 0, -5, -8);
    capPath.AddLine(-5, -8, 5, -8);
    arrowPen.CustomEndCap = new CustomLineCap(capPath, null); // OK
    

    修正你的例子

    triangleHeight 从y。这会将箭头的尖端放置在0,0处(这是直线末端的坐标),这很可能是您想要的结果,并将三角形的底部放置在0,0处 -triangleHeight .

    float radius = 5.0f;
    float triangleSide = 3.0f * radius / (float)Math.Sqrt(3.0f);
    float triangleHeight = 3.0f * radius / 2.0f;
    GraphicsPath capPath = new GraphicsPath();
    capPath.AddLines(new PointF[] {
        new PointF(-triangleSide / 2.0f, -triangleHeight),
        new PointF(triangleSide / 2.0f, -triangleHeight),
        new PointF(0, 0) }
    );
    arrowPen.CustomEndCap = new CustomLineCap(capPath, null);
    

      Dim points() As PointF = New PointF() { _ 
          New PointF(-triangleSide / 2, -triangleHeight), _ 
          New PointF(triangleSide / 2, -triangleHeight), _
          New PointF(0, 0) }
      path.AddLines(points)
    
        4
  •  0
  •   Fabian    4 年前

    在我的情况下,我已经使长度的上限部分取决于容器的宽度。每当我缩小窗体超过某个限制时,我的程序总是异常停止。 然后我发现异常是在任何段的长度达到1时抛出的。