Can subgraph size changed if ports are added or removed?

Similar to colored Node in samples.
Can a subgraph change its size on adding or removing ports?
The subgraphs in subgraph app, adds ports but keeps the subgraph size same which results in overlapping of ports. When ports are added on left of the subgraph its height should be increased if space is not sufficient to layout the ports.
In colored node, size of node is changed on addition.
Currently there are methods in subgraph to layout the ports but taking rectangle size as input to it.
I want to change the size of the subgraph as ports on the subgraph can not be put in given rectangle. I want to change the size of subgraph (i.e. height) in both collapsed and expanded condition if height is not sufficient to place the nodes.
How can it be done without affecting layout handle method in the subgraph?

The way you expand the inside of an expanded or collapsed subgraph is to modify ComputeInsideMargins.

I suppose you could override that and add some minimum return value based on # of ports.

LayoutPorts shows how to count ports.

Basically… make this smarter:

public override RectangleF ComputeInsideMargins(GoObject ignore)
{
  RectangleF r = base.ComputeInsideMargins(ignore);
  if (r.Height < 400) r.Height = 400;
  return r;
}

Thank you very much for the reply.
Extremely sorry, I trouble you again and again.
I will try the code provided by you along with counting number of left side and right side ports and finding maximum required size and setting the rectangle height to that size if it is less than required max size. I hope, it will not change my handle location.

Thanks once again.

Thanks…It is working fine without affecting handle layout.