12

An in house application that I'm developing is behaving strange on a Windows 7 (64 bit) PC.

If I create an instance of a PrintDialog, and call it's ShowDialog() method, the method immediately returns DialogResult.Cancel without showing the printer dialog form.

The Windows 7 PC does have printers installed (with a working default printer).

PrintDialog printDialog = new PrintDialog();

printDialog.PrinterSettings.Copies = 2;
printDialog.AllowCurrentPage = false;
printDialog.AllowPrintToFile = false;
printDialog.AllowSelection = false;
printDialog.AllowSomePages = false;
DialogResult dialogResult = printDialog.ShowDialog(this);

if (dialogResult == DialogResult.Cancel)
    return;

Any clues why this is happening?

dovid
  • 6,354
  • 3
  • 33
  • 73
Bryan
  • 3,224
  • 9
  • 41
  • 58

1 Answers1

30

Set printDialog.UseEXDialog to true to work around this bug.

In .Net 3.5, MSDN mentions this potential problem when documenting UseEXDialog:

When this property is set to true, ShowHelp and ShowNetwork will be ignored as these properties were made obsolete for Windows 2000 and later versions of Windows. Also, The PrintDialog class may not work on AMD64 microprocessors unless you set the UseEXDialog property to true.

(My emphasis.)

The same page for .Net 4 and .Net 4.5 don't include the emphasized bit, so perhaps it's fixed in those versions.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Stefan Schultze
  • 9,240
  • 6
  • 35
  • 42
  • 2
    Thanks, For anyone else interested, the MSDN article for UseExDialog has more comments about this - http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.useexdialog.aspx – Bryan Nov 16 '09 at 10:38
  • My initial googling didn't find anything useful, however now that I know the solution, there is plenty of reading material on this issue http://www.google.co.uk/search?q=UseExDialog+cancelled – Bryan Nov 16 '09 at 10:42
  • Thanks. Very intuitive of Microsoft to hide functionality after something with a name like that. – Carra Aug 31 '12 at 09:39