Draw Line with Arrow head


Author
Message
Ashley Davy
Ashley Davy
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
Posts: 36, Visits: 119
How do I programmatically draw a line with an Arrow head at the end?
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
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


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search