Draw Line with Arrow head


https://www.nevron.com/Forum/Topic13002.aspx
Print Topic | Close Window

By Ashley Davy - 4 Years Ago
How do I programmatically draw a line with an Arrow head at the end?
By Nevron Support - 4 Years Ago
The following function creates a line shape:

private NShape CreateLineShape(NPoint start, NPoint end, NStroke stroke)
{
  NShape shape = new NShape();
    
  shape.Init1DShape(EN1DShapeXForm.Vector);
  shape.Height = 0;

  NGeometry geom = new NGeometry();
  NMoveTo moveTo = geom.MoveTo(0.0d, 0.5d);
  moveTo.Relative = true;
  moveTo.ShowFill = false;
  geom.Stroke = stroke;
  geom.LineTo(1.0d, 0.5d).Relative = true;
  shape.Geometry = geom;

  shape.SetBeginPoint(start);
  shape.SetEndPoint(end);

  return shape;
}

If you would like the line to have the default appearance of connectors you need to add the "Connectors" user class to it:

// create a line with connector styling
    NShape line = CreateLineShape(new NPoint(10, 10), new NPoint(100, 200), new NStroke(1, NColor.Black));
    line.UserClass = "Connector";
    drawing.ActivePage.Items.Add(line);

alternatively, you can create a line with specific arrowheads like this:

// create a line with specific arrowheads
      NShape line = CreateLineShape(new NPoint(10, 10), new NPoint(100, 200), new NStroke(1, NColor.Black));
      line.Geometry.BeginArrowhead = new NArrowhead(ENArrowheadShape.Circle, 10, 10);
      line.Geometry.EndArrowhead = new NArrowhead(ENArrowheadShape.Triangle, 10, 10);
      drawing.ActivePage.Items.Add(line);