Printing nested GoSubGraph

I came up with some code to print just the objects that are selected by setting the Printable property. I found out that I had to recurse through GoSubGraphs and set the children GoObject’s Printable property as well.
If I had GoSubGraphs nested inside of each other, I also found that I had to set the containing GoSubGraph.Printable to true or else nothing would print.
Is there a way to print just the nested GoSubGraph and not its parent?
Thanks

If CanPrint() for the SubGraph returns false, the Paint method for the subgraph won't be called, so no children will be asked to Paint.
Note that the painting of the subgraph (as opposed to it's children) all happens in PaintDecoration. PaintDecoration also calls CanPrint, but you can probably override PaintDecoration to do a "if I'm printing, do I really want to print this subgraph?" sort of a check.
I added a PrintsChildren property and overroad CanPrint():
[code]
public override bool CanPrint()
{
return base.CanPrint() || PrintsChildren;
}
[/code]
But in my override of PaintDecoration(), I do this:
[code]
protected override void PaintDecoration(Graphics g, GoView view)
{
if (Printable)
base.PaintDecoration(g, view);
}
[/code]
That gets me closer to the results I want. Only the nested GoSubGraph and its children print, but it is positioned as if the parent GoSubGraphs were still there.
I have a feeling that this is because GoDocument.ComputeBounds() also calls CanPrint(). Instead of overriding CanPrint() is there another property or method I could override that would still iterate through the GoSubGraph's children?
Thanks for your help.
Check the Reference Guide for GoView.PrintDocumentSize and GoView.PrintDocumentTopLeft.
You can call the static method GoDocument.ComputeBounds(IGoCollection, GoView) to determine the extent of any collection of objects. That method takes an optional GoView argument to allow consideration of how much area each object actually takes when painted or printed in that view, since for each object the result of ExpandPaintBounds(RectangleF, GoView) may be larger than then the object's Bounds.

Thanks for the tips. At first I didn’t get it, so I set this problem aside and twisted my brain around some WPF. When I came back to this, it made sense.

I had already sub-classed GoView, so once I overrode PrintDocumentSize and PrintDocumentTopLeft, everything worked beautifully. One of the other keys was overriding of GoSubGraph's CanPrint() so that the if PrintsChildren (a new property) is true, Paint gets called for its children even if the GoSubGraph itself is not Printable. Here's the code I came up with, for the benefit of others:
Code from form doing the printing:
[code]
private void Print()
{
bool changedPrintable = false;
goView1.PrintScale = goView1.DocScale;
changedPrintable = SetPrintSelected();

goView1.Print();
// or for PrintPreview:
// goView1.PrintPreview();

if (changedPrintable)
ClearPrintSelected();
}

private bool SetPrintSelected()
{
bool changedPrintable = false;
if (goView1.Selection.Count > 0)
{
changedPrintable = true;
foreach (GoObject obj in goView1.Document)
{
obj.Printable = goView1.Selection.Contains(obj);
if (obj is MySubGraph)
{
var sgQuestion = (MySubGraph)obj;
if (SetPrintSelectedChildren(sgQuestion))
sgQuestion.PrintsChildren = true;
}
}
}
return changedPrintable;
}<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

private bool SetPrintSelectedChildren(MySubGraph)

{
bool printable = sg.Printable;

foreach (GoObject sgObj in sg)
{
if (goView1.Selection.Contains(sgObj))
sgObj.Printable = true;
else
sgObj.Printable = sg.Printable;

printable = printable || sgObj.Printable;

if (sgObj is MySubGraph)
{
var sgQuestion = (MySubGraph)sgObj;
if (SetPrintSelectedChildren(sgQuestion))
{
printable = true;
sgQuestion.PrintsChildren = true;
}
}
}
return printable;
}

private void ClearPrintSelected()
{
foreach (GoObject obj in goView1.Document)
{
obj.Printable = true;
if (obj is GoSubGraph)
{
GoSubGraph sg = (GoSubGraph)obj;
foreach (GoObject sgObj in sg)
{
sgObj.Printable = true;
if (sgObj is GoSubGraph)
ClearPrintSelectedChildren((GoSubGraph)sgObj);
}
}
}
goView1.Document.ComputeBounds();
}

private void ClearPrintSelectedChildren(GoSubGraphsg)
{
foreach (GoObject sgObj in sg)
{
sgObj.Printable = true;
sg.PrintsChildren = false;
if (sgObj is GoSubGraph)
{
ClearPrintSelectedChildren((GoSubGraph)sgObj);
}
}
}
[/code]

Code from GoView sub-class:
[code]
public override SizeF PrintDocumentSize
{
get
{
if (Selection.Count > 0)
return GoDocument.ComputeBounds(Selection, this).Size;
else
return base.PrintDocumentSize;
}
}

public override PointF PrintDocumentTopLeft
{
get
{
if (Selection.Count > 0)
return GoDocument.ComputeBounds(Selection, this).Location;
else
return base.PrintDocumentTopLeft;
}
}
[/code]
I also sub-classed GoSubGraph (referenced above as MySubGraph):
[code]
private bool _PrintsChildren = false;

public bool PrintsChildren
{
get
{
return _PrintsChildren;
}
set
{
_PrintsChildren = value;
}
}

public override bool CanPrint()
{
return base.CanPrint() || PrintsChildren;
}

protected override void PaintDecoration(Graphics g, GoView view)
{
if (Printable)
base.PaintDecoration(g, view);
}
[/code]