NShape Programmer Tasks
Setting the Shape Color Programmatically in the Template

<< Click to Display Table of Contents >>

Navigation:  Programmer Tasks > Changing the Shape Color Programmatically >

NShape Programmer Tasks
Setting the Shape Color Programmatically in the Template

Previous pageReturn to chapter overviewNext page

When a program changes the color of a shape template, all shapes that belong to this template will be affected (unless their fill style has been detached from the template).

How to Assign a Standard Fill Style to a Shape's Template:

Standard fill styles are available as properties in the Design class. You must make sure that the shape and therefore its template shape have indeed a FillStyle property, e.g. because they implement IPlanarShape.

((IPlanarShape)myShape.Template.Shape).FillStyle = myProject.Design.FillStyles.Blue;

How to Assign a Custom Fill Style to a Shape's Template:

Custom fill styes and standard fill styles can also be identified by their name. Make sure to use the name of a style not its title, which is for display purposes only and not necessarily unique:

((IPlanarShape)myShape.Template.Shape).FillStyle = myProject.Design.FillStyles["myCustomFillStyle"];

How to Re-Assign the Template Fill Style to a Shape:

When you set the shape's fill style to null, it uses its template's fill style again:

myShape.FillStyle = null;