G
Guest
I have an application that prints documents that it creates. It uses what I
believe is a standard .NET way of doing so, like this:
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
PrintDialog PrintDialog1 = new PrintDialog();
PrintDialog1.Document = pd;
DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
this.streamToPrint = new StreamReader(FileName);
pd.Print();
this.streamToPrint.Close();
}
I have written a pd_PrintPage method that does the actual graphics commands
to print each page. This all works fine.
Where I have encountered a problem is in implementing selective page
printing. I have been able to activate the page range in the dialog like this:
PrintDialog1.PrinterSettings.FromPage=1;
PrintDialog1.PrinterSettings.ToPage=100;
PrintDialog1.AllowSomePages=true;
I had hoped that this was all I needed to do, since the printing routine
clearly knows what page it is printing as it displays the page number while
doing so, and generally pages the document properly. But it always prints all
the pages regardless of what the users selects. I have this in my page print
method, which allows me to determine whether this page should be printed or
not:
PrinterSettings PrSe=ev.PageSettings.PrinterSettings;
if(PrSe.PrintRange==PrintRange.SomePages&&
(PrSe.FromPage>PageNumber||PrSe.ToPage<PageNumber))
// do not print this page.
But I can not figure out a way to tell Windows not to print the page. If I
simply do not execute the contents of the print page routine, I still get a
blank page. How do I not print the page entirely? Alternatively, is there an
example somewhere of using the AllowSomePages and FromPage and ToPage
members? Thanks.
believe is a standard .NET way of doing so, like this:
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
PrintDialog PrintDialog1 = new PrintDialog();
PrintDialog1.Document = pd;
DialogResult result = PrintDialog1.ShowDialog();
if (result == DialogResult.OK)
{
this.streamToPrint = new StreamReader(FileName);
pd.Print();
this.streamToPrint.Close();
}
I have written a pd_PrintPage method that does the actual graphics commands
to print each page. This all works fine.
Where I have encountered a problem is in implementing selective page
printing. I have been able to activate the page range in the dialog like this:
PrintDialog1.PrinterSettings.FromPage=1;
PrintDialog1.PrinterSettings.ToPage=100;
PrintDialog1.AllowSomePages=true;
I had hoped that this was all I needed to do, since the printing routine
clearly knows what page it is printing as it displays the page number while
doing so, and generally pages the document properly. But it always prints all
the pages regardless of what the users selects. I have this in my page print
method, which allows me to determine whether this page should be printed or
not:
PrinterSettings PrSe=ev.PageSettings.PrinterSettings;
if(PrSe.PrintRange==PrintRange.SomePages&&
(PrSe.FromPage>PageNumber||PrSe.ToPage<PageNumber))
// do not print this page.
But I can not figure out a way to tell Windows not to print the page. If I
simply do not execute the contents of the print page routine, I still get a
blank page. How do I not print the page entirely? Alternatively, is there an
example somewhere of using the AllowSomePages and FromPage and ToPage
members? Thanks.