NShape Programmer Tasks
Setting the Shape Color Programmatically Directly at the Shape

<< Click to Display Table of Contents >>

Navigation:  Programmer Tasks > Changing the Shape Color Programmatically >

NShape Programmer Tasks
Setting the Shape Color Programmatically Directly at the Shape

Previous pageReturn to chapter overviewNext page

The shape's color is defined by its FillStyle property. If this property is null, the shape takes its fill style from its template. Setting this property assigns a private fill style to the shape. Fill styles are part of the project's design and can be identified by their name. Standard fill styles additionally have a property in the Design class.

How to Set the Shape Color by Assigning a Standard Fill Style:

Identify the desired standard fill style in the design and assign it to the shape. For example the standard red fill style:

myShape.FillStyle = myProject.Design.FillStyles.Red;

Notes

When you assign an explicit private fill style to a shape the fill style is detached from the template and future changes to the template's fill style will not affect the shape anymore. To re-attach the shape's fill style to the template, assign null/Nothing to the shape's fill style.

How to Set the Shape Color by Assigning a Custom Fill Style:

Identify the desired fill style through its name and assign it to the shape. For example a custom fill style named MyNewFillStyle:

myShape.FillStyle = myProject.Design.FillStyles["MyNewFillStyle"];

Notes

Above notes apply here as well.