Eric Carr
New member
Hi. I'm embarrased that I'm having so much trouble with something so simple, but here it goes.
In my code I have a PrintDialog that allows the user to select a page range to print (the AllowSomePages property is set to true), but when a range is selected (ex: pages 2-3) in the dialog it still print all the pages in the document. I've been following the API documentation as well as articles/tutorials online but I still can't get it to work. Multiple copies print fine. Print to File works fine. Just the page range doesn't work.
I've tried manually setting the ToPage and FromPage members in the PrintDocument's PrinterSettings and DefaultPrinterSettings members as well as in the PrintDialog's PrinterSettings member. I've also set the MinimumPages and MaximumPages in each one with no success.
Here's some test code I've been trying to solve the problem with (...well the latest version anyway). The code is on a WinForm with one button (Button2). I really don't know what I'm doing wrong. Any help at solving my problem would be very appreciated.
In my code I have a PrintDialog that allows the user to select a page range to print (the AllowSomePages property is set to true), but when a range is selected (ex: pages 2-3) in the dialog it still print all the pages in the document. I've been following the API documentation as well as articles/tutorials online but I still can't get it to work. Multiple copies print fine. Print to File works fine. Just the page range doesn't work.
I've tried manually setting the ToPage and FromPage members in the PrintDocument's PrinterSettings and DefaultPrinterSettings members as well as in the PrintDialog's PrinterSettings member. I've also set the MinimumPages and MaximumPages in each one with no success.
Here's some test code I've been trying to solve the problem with (...well the latest version anyway). The code is on a WinForm with one button (Button2). I really don't know what I'm doing wrong. Any help at solving my problem would be very appreciated.
VB.NET:
Public PageCount As Integer
WithEvents Doc As New PrintDocument
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim Diag As New PrintDialog
Diag.Document = Doc
Diag.AllowSomePages = True
Diag.PrinterSettings.MinimumPage = 1
Diag.PrinterSettings.MaximumPage = 3
Diag.PrinterSettings.FromPage = 1
Diag.PrinterSettings.ToPage = 3
If Diag.ShowDialog() = DialogResult.OK Then
PageCount = 1
Doc.Print()
End If
End Sub
Private Sub PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles Doc.PrintPage
Dim f As New Font(FontFamily.GenericSerif, 18, FontStyle.Regular)
e.Graphics.DrawString("Page #" & PageCount, f, Brushes.Black, 10, 10)
PageCount += 1
If PageCount <= 3 Then
e.HasMorePages = True
End If
End Sub