GoSubGraph CollapsedObject on uncollapsed area

I’m having an odd problem with the CollapsedObject on a class derived off of GoSubGraph. I create my sub graph, and add it to the document, then I add my nodes to it (all done programmatically). But when the result shows up, it looks like this:

As you can see The CollapsedObject is showing up in the top left. Here is my constructor where I define the CollapsedObject:

public MySubSetGoSubGraph(Guid guid)
: base(guid)
{
GoImage img = new GoImage();
img.Image = MySubSetImage;
img.Selectable = false;
CollapsedObject = img;
//Collapse();
//Expand();
}

The two lines at the bottom which I commented out, actually fix the problem and it looks like this:

Any ideas? I don’t really like my solution, and I think this might be related to another problem that I’m having with collapsing my sub graph, but one problem at a time…

The setter for CollapsedObject is supposed to set it to “not visible” if the subgraph is expanded, but my guess is that it is still visible for some reason.

The other thing you can do is override CreateCollapsedObject, as the subgraphapp sample shows:
// If you want to display an image when collapsed,
// add this override (or set CollapsedObject)
// protected override GoObject CreateCollapsedObject() {
// GoImage img = new GoImage();
// img.Selectable = false;
// img.Visible = false;
// img.Printable = false;
// img.Name = ...
// img.Size = new SizeF(img.Image.Width, img.Image.Height);
// this.CollapsedSize = img.Size;
// return img;
// }

Thanks! That worked like a charm. Now for my second problem. After adding all of the subgraphs and adding all of the nodes and edges, I need to collapse some of the subgraphs. but when I call Collapse(), the nodes are moved, and the subgraph resizes to fit them, but it is not replaced by the CollapsedObject.

Do I need to wait for something or do something else before calling Collapse()?

But if you expand/collapse that subgraph by clicking the [-], everything is OK?

yes.

[code] GoSubGraph sg = new GoSubGraph();
sg.Text = “subgraph”;
sg.BackgroundColor = Color.LightBlue;
sg.BorderPenColor = Color.Blue;
sg.Corner = new SizeF(5, 5);
sg.PickableBackground = true;

  GoDrawing fire = new GoDrawing(GoFigure.FireHazard);
  fire.Selectable = false;
  // set these two properties if leaving GoSubGraph expanded initially
  //fire.Visible = false;
  //fire.Printable = false;
  fire.FillSimpleGradient(Color.Orange, Color.Red, GoObject.MiddleTop);
  fire.Size = new SizeF(40, 40);
  sg.CollapsedObject = fire;
  sg.CollapsedLabelSpot = GoObject.MiddleBottom;

  GoBasicNode bn1 = new GoBasicNode();
  bn1.Text = "bn1";
  bn1.Location = new PointF(200, 200);
  sg.Add(bn1);

  GoBasicNode bn2 = new GoBasicNode();
  bn2.Text = "bn2";
  bn2.Location = new PointF(350, 300);
  sg.Add(bn2);

  GoLink link = new GoLink();
  link.ToArrow = true;
  link.FromPort = bn1.Port;
  link.ToPort = bn2.Port;
  sg.Add(link);

  sg.Collapse();
  goView1.Document.Add(sg);[/code]

Running this code produces:

Clicking on the handle expands the subgraph to produce:

The Handle does not move when the user clicks on it. Of course clicking on it again results in the first image again.

Thanks for your help. There was a bug in my code which I was able to ferret out.