PrintPreview diagrams in different layers

I am allowing my users to draw diagrams on different layers(GoLayer) in a GoDocument. when a user wants to view the PrintPreview of the diagrams in all the layers, I want to display the diagrams in different layers on different pages in the print document. I am not sure how I can do that. Currently, the diagrams are ovelapping. Can anyone help me with this?

Thanks in advance.


You have to make use of the .NET PrintController class. Something like:
/* USE:
PrintDocument pd = new PrintDocument();
pd.DocumentName = “Multiple layer test”;
pd.PrintController = new MultiLayerPrintController(myView.Document);
PrintDialog dlg = new PrintDialog();
dlg.Document = pd;
if (dlg.ShowDialog() != DialogResult.Cancel) {
public class MultiLayerPrintController : StandardPrintController {
public MultiLayerPrintController(GoDocument doc) {
myView = new GoView(doc);
myLayers = doc.Layers.CopyArray();
private GoView myView = null;
private GoLayer[] myLayers = null;
private int myLayerIndex = 0;
public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e) {
GoLayer currentLayer = myLayers[myLayerIndex];
foreach (GoLayer layer in myView.Layers.CopyArray()) {
if (layer.IsInDocument) {
layer.AllowPrint = (layer == currentLayer);
return base.OnStartPage(document, e);
public override void OnEndPage(PrintDocument document, PrintPageEventArgs e) {
base.OnEndPage(document, e);
if (!e.HasMorePages) {
e.HasMorePages = (myLayerIndex < myLayers.Length);
public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
document.PrintPage += new PrintPageEventHandler(myView.PrintDocumentPage);
myLayerIndex = 0;
base.OnStartPrint(document, e);
Of course you can adapt this code to the requirements of your particular application…

Oops, now that I reread your original post, I see that you were talking about PrintPreview, not just plain printing.
There is a PreviewPrintController class that .NET offers, but it doesn’t seem to use a custom print controller. I don’t know why not, but I guess if you want to use PrintPreviewDialog or Control, you would need to override PreviewPrintController.GetPreviewPageInfo. I haven’t tried that.

Thank You walter. I tried the samething. It seems that it is overwriting the same page again and again. Anyways, this is a good starting point for me.

Thanks Again.