Skip to main content

Changing the color and size of the shape

To change the color of a shape, modify the properties of the IShapeStyle object. To change the size of a shape, use the SetSizeAt method of the INode object. Please check the available colors at Link.

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, terminate the process
c.App.Output.WriteLine("sample", "The diagram is not displayed");
return;
}

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

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

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

Alternatively, you can change the size using System.Drawing.Size. In that case, 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);
}