Skip to main content

Change the color and size of a shape

To change the color of a shape, change the properties of the IShapeStyle object. To change the size of a shape, use the SetSizeAt method of the INode object. Please check Link for the colors that can be changed.

public void ChangeColorAndSize(ICommandContext c, ICommandParams p) 
{
//Get the currently displayed diagram
IDiagram diagram = c.App.Workspace.CurrentEditor as IDiagram;
if (diagram == null)
{
//If the diagram is not displayed, exit the process
c.App.Output.WriteLine("sample", "Diagram is not displayed");
return;
}

//Get the displayed node on the diagram
INode node = diagram.Nodes.FirstOrDefault();
if (node ​​== null)
{
//If the node is not displayed, exit the process
c.App.Output.WriteLine("sample", "Node is not displayed");
return;
}

//Get the node style and change the color
IShapeStyle style = node.Style;
style.BackColor = "Red"; //Change the background color to the default value
style.ForeColor = "#ffffff"; //Change the foreground color in code

//Change the size of the node
node.SetSizeAt(100, 100);
}

You can also change the size with System.Drawing.Size. To do this, use the SetSize method of the INode object.

public void SetSize(ICommandContext c, ICommandParams p) 
{
//Omitted
//Change the size of the node
System.Drawing.Size size = new System.Drawing.Size(200, 100);
node.SetSize(size);
}