Page Setup

I want to change the page setup property for a GoView Document in the print preview mode. Does any one has any sample code to accomplish this??

protected override void PrintPreviewShowDialog(PrintDocument pd) { pd.DefaultPageSettings.Landscape = true; pd.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); base.PrintPreviewShowDialog(pd); }

Hi Walter,

I want to use a PageSetupDialog to change Page Setting.
But how to get PrintDocument object to put the dialog.
(See red code)
void PageSetup()
{
PageSetupDialog dlg = new PageSetupDialog();
dlg.Document = ??;
if(dlg.ShowDialog()==ResultDialog.OK)
{
// change Page Setting here
}
}

new PrintDocument()
But note that if you were overriding the GoView.Print…ShowDialog methods, the PrintDocument is passed as an argument.

Hi Walter

I have a question.
How to set view.PrintScale after setting Page Setup?
I used GoDrawView. I want to ruler’s suit with Page Setup setting

I don’t understand why the value of GoView.PrintScale should depend on the choices the user makes in PageSetupDialog.

Because I want area of view change correlatively with the choices the user makes in PageSetupDialog.

If you are using a GoSheet (i.e. GoView.BackgroundHasSheet is true), then it makes sense to adjust its properties based on the results of the PageSetupDialog. That’s the purpose of the GoSheet.UpdateBounds method, which takes a PageSettings and (normally) the GoView.PrintScale as arguments.
But maybe you are trying to fit everything onto one page, and thus the page settings (page size and margins) affects what scale you want to print at. OK, how about something like:
protected DialogResult ShowPageSetupDialog(PrintDocument pd) {
PageSetupDialog dlg = new PageSetupDialog();
dlg.Document = pd;
DialogResult result = dlg.ShowDialog();
if (result != DialogResult.OK) return result;
SizeF docsize = this.PrintDocumentSize;
if (docsize.Width > 1 || docsize.Height > 1) {
Rectangle b = pd.DefaultPageSettings.Bounds;
Margins m = pd.DefaultPageSettings.Margins;
float w = b.Width - (m.Left + m.Right);
float h = b.Height - (m.Top + m.Bottom);
float ratio = Math.Min(w/docsize.Width, h/docsize.Height);
if (ratio > 1)
ratio = 1;
this.PrintScale = ratio;
return DialogResult.OK;
}
return DialogResult.Cancel;
}
protected override DialogResult PrintShowDialog(PrintDocument pd) {
if (ShowPageSetupDialog(pd) == DialogResult.OK) {
return base.PrintShowDialog(pd);
} else {
return DialogResult.Cancel;
}
}
protected override void PrintPreviewShowDialog(PrintDocument pd) {
if (ShowPageSetupDialog(pd) == DialogResult.OK) {
base.PrintPreviewShowDialog(pd);
}
}

Thank Walter,
I was used UpdateBounds method for a GoSheet.
It’s OK if using portrait mode.
When I used landscape mode, it treated like portrait mode.

And I want to use centimeter stead of inch (default) in rulers.

Help me resolve these problem.

I’ll look into the landscape/portrait issue when I get a chance. Although the Microsoft sample code doesn’t seem to special case whether it is landscape or not to determine what the “Width” and “Height” really are.
GoRuler uses pixels by default, not metric or English units. What is the value of GoRuler.Units for your application?

I’m still looking forward to solution for landscape problem.
And shrinked view problem at first time set page setup

You should just change the size of the GoView.Sheet.Paper:
goView1.BackgroundHasSheet = true;
PrintDocument printdoc = new PrintDocument();
PageSettings pageset = printdoc.DefaultPageSettings;
//pageset.Landscape = true;
PaperSize ps = pageset.PaperSize;
SizeF sz = new SizeF(ps.Width/goView1.PrintScale, ps.Height/goView1.PrintScale);
RectangleF r = (pageset.Landscape ? new RectangleF(0, 0, sz.Height, sz.Width) : new RectangleF(0, 0, sz.Width, sz.Height));
goView1.Sheet.Paper.Bounds = r;

Thank Walter,
It’s resolved.