开发者

PageSetupDialog not returning PageSize correctly

I'm trying to set up the print page for a document, using PageSetupDialog.

Before I open the dialog, the document is set correctly, page size and page source are set correctly too. But when I return from the dialog after select a different paper size and paper source, the paper size is not correctly reflected, while the paper source is fine. Yes, I am pressing OK button.

This issue is not new but so far there has been no proper answer.

    PageSetupDialog dlgPageSetup = new PageSetupDialog();
 开发者_如何学JAVA   dlgPageSetup.Document = this.printDocument1; //this is fine, assume that.
    dlgPageSetup.PageSettings.PaperSize = new PaperSize("My Custom", 1012, 800);
    dlgPageSetup.PageSettings.PaperSource.SourceName = "Envelope";
    if (dlgPageSetup.ShowDialog(this) == DialogResult.OK) {
        System.Diagnostics.Trace.WriteLine("DEBUG: "
              + dlgPageSetup.PageSettings.PaperSize);
        System.Diagnostics.Trace.WriteLine("DEBUG: "
              + dlgPageSetup.PageSettings.PaperSource);
    }

I'm using .Net 2.0, VS 2k5.

Link to original issue.

I am guessing this still is a bug, and its related to custom page size. Has anybody got solution for this problem?


I worked around the problem by:

  1. setting the Document property on the pagesettings dialog to (none)
  2. recreating the print document if I see that it is set to a custom PageKind

So before I open the printsettings dialog, I check the PageKind of the print document, recreate if necessary, and then open the dialog.

if(printDocument1->DefaultPageSettings->PaperSize->Kind == 
    System::Drawing::Printing::PaperKind::Custom)
{
  RecreatePrintDocument();
}
pageSetupDialog1->PageSettings = printDocument1->DefaultPageSettings;
pageSetupDialog1->PrinterSettings = printDocument1->PrinterSettings;
Windows::Forms::DialogResult dresult = pageSetupDialog1->ShowDialog();

In RecreatePrintDocument(), I create a new printdocument and assign the handler, that sort of thing.

This isn't a great solution, because we just forget the page settings if the user chooses a custom page kind, but it's something to start with.


This is a known bug. Till .NET 3.5, it is still reproducible. More details on thread http://social.msdn.microsoft.com/forums/en-US/winforms/thread/81bb2cea-8d47-4ddc-a174-14d6bc196de7/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜