Nevron Forum

How to fill a custom shape with color or texture?

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

By Marius Bucur - Tuesday, November 17, 2009

I am trying to fill a custom shape with color or a texture, but so far i have no luck. Basically my code look like this:

GraphicsPath graphicsPath = new GraphicsPath();

PointF[] points = new PointF[]
{
new PointF(0, 0),
new PointF(0, 20),
new PointF(20, 20),
new PointF(20, 0),
};
graphicsPath.AddPolygon(points);
//InitTextures();
NCompositeShape shape = new NCompositeShape();
shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.OpenFigure));
shape.UpdateModelBounds();
//NImageFillStyle img = new NImageFillStyle(this.textures["bricks"] as Bitmap);
//img.TextureMappingStyle.MapMode = MapMode.RelativeToObject;
//shape.Style.FillStyle = img;
shape.Name = "Basic Wall";
shape.Text = "Basic Wall";


shape.Style.FillStyle = new NColorFillStyle(Color.AliceBlue);
shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0, 0, 0x88));
By Ivo Milanov - Tuesday, November 17, 2009

Hi Marius,

The custom path you create must be marked as ClosedFigure if the diagram is to attempt to fill the path interior:

NCompositeShape shape = new NCompositeShape();
shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.ClosedFigure));

Best regards,
Ivo
By Marius Bucur - Tuesday, November 17, 2009

nvm, its solved. I should be using PathType.ClosedFigure in this line: shape.Primitives.AddChild(new NCustomPath(graphicsPath, PathType.OpenFigure));

But i have another question, is it possible to make a texture pattern repeat and not stretch when i resize the custom shape ?
By Ivo Milanov - Tuesday, November 17, 2009

Check out this topic in the .NET Vision Documentation:

Framework > Presentation Layer > Graphics > Appearance Styles > Fill Styles > Texture Mapping Style

It basically outlines the possible ways in which a texture can be mapped. To make the image Tiled used this code:

NImageFillStyle imageFill = ...;
imageFill.TextureMappingStyle.MapLayout = MapLayout.Tiled;

Best regards,
Ivo