Nevron Forum

Changing StrokeStyle of a Path

https://www.nevron.com/Forum/Topic5279.aspx

By Volvick Derose 1 - Tuesday, June 28, 2011

I try to create a composite shape; the following code works fine for NRectangle shape, but not NRectangle path

NStrokeStyle strokeStyle = new NStrokeStyle();
strokeStyle.Factor = 3;
strokeStyle.Width = new NLength(3, NGraphicsUnit.Point);
outsideShape.Style.StrokeStyle = strokeStyle;
By Nevron Support - Wednesday, June 29, 2011

Hi Volvick,

You should always use one of NStyle.SetStyle static methods for setting the style of any element! These methods automatically check if the Style of the given element is null and create it if it is. In this way you will never have a null reference exception when setting one of the styles of an element but you forget to check if its Style property is null. The following is a simple example:

 

NRectanglePath rectPath = new NRectanglePath(300, 300, 100, 100);

 

// Always use one of the NStyle.SetStyle methods for setting the style of any element!

NStyle.SetFillStyle(rectPath, new NColorFillStyle(KnownArgbColorValue.Red));

 

NCompositeShape shape = new NCompositeShape();

shape.Primitives.AddChild(rectPath);

document.ActiveLayer.AddChild(shape);

By Volvick Derose 1 - Wednesday, June 29, 2011

Hopefully this one works

NStrokeStyle strokeStyle = new NStrokeStyle();
strokeStyle.Factor = 3;
strokeStyle.Width = new NLength(3, NGraphicsUnit.Point);
NStyle.SetStrokeStyle(outsideShape, strokeStyle);