1

If I create a simple WinForms PrintDialog as such:

PrintDialog print_dialog = new PrintDialog();
print_dialog.UseEXDialog = true;

// Setup dialog defaults
print_dialog.AllowSomePages = true;    // Setting this shows a default value of "0"
print_dialog.AllowCurrentPage = true;
print_dialog.AllowSelection = false;

if (print_dialog.ShowDialog() == DialogResult.OK) {
    Debug.WriteLine("Printing");
}

I get the following result, where the Page Range -> Pages has a default value of "0" (circled):

PrintDialog with Page Range 0

To me that looks unprofessional. Every other program I've looked at has that value blank until it is filled in by the user. Is there anything I can do to make the default show as blank?

Even if I try to hack this by attempting to set the value manually to something that might make more sense to my users than Pages: 0, such as:

print_dialog.PrinterSettings.FromPage = 1;

I get an exception: Value FromPage is out of range.

What can I do?

DelftRed
  • 196
  • 1
  • 11
  • You should also set this property PrinterSettings.PrintRange = PrintRange.SomePages before you set frompage property – lyz Nov 06 '16 at 10:42
  • 1
    @lyz Setting `print_dialog.PrinterSettings.PrintRange = PrintRange.SomePages` is not compulsory, it just sets 'Pages:' radio button selected. The error is because the specified value is out of range and it's just because the OP didn't set `print_dialog.PrinterSettings.ToPage` value and it uses its default value which is 0. The `FromPage` should be less than or equals to `ToPage`. – Reza Aghaei Nov 06 '16 at 10:56

1 Answers1

1

You should specify both FromPage and ToPage values:

//To show 1 in front of Pages:
print_dialog.AllowSomePages = true;  
//Default value for PrinterSettings.MinimumPage is 0
//Default value for PrinterSettings.MaximumPage is 9999
print_dialog.PrinterSettings.FromPage = 1;
print_dialog.PrinterSettings.ToPage = 1;

The FromPage value should be less than or equals to the ToPage.

Also both values should be in range specified by MinimumPage and MaximumPage.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Let me know if you have any question about applying the answer :) – Reza Aghaei Nov 08 '16 at 09:43
  • Thank you Reza. How strange that you need to specify both to avoid such an enigmatic error, but that does work! At least I can set it to something sensible. No way to set it to blank? – DelftRed Nov 10 '16 at 10:05
  • 1
    You're welcome :) Since the property is `int` you should set it to an integer. Have you ever seen it to be empty in a print dialog? I've never seen. Have you? – Reza Aghaei Nov 10 '16 at 10:48
  • 1
    Hmmm... no indeed I haven't! You are right (once again! :). I looked at a lot of print dialog boxes in a lot of programs, and those that had a blank Pages field were actually subtly (or very) different from the .NET PrintDialog, while those that were identical did not have a blank field. So I didn't actually look closely enough, it seems. Cheers! :) – DelftRed Nov 25 '16 at 01:30