Profile Picture

Draw Line with Arrow head

Posted By Ashley Davy 4 Years Ago
Author
Message
Ashley Davy
Question Posted 4 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 36, Visits: 119
How do I programmatically draw a line with an Arrow head at the end?

Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
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);



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic