不知道为什么你的问题被否决了,对我来说似乎很合理????
无论如何,我注意到 PrintDialog 的一些事情(可能会或可能不会回答您的问题)。
首先,它只是 windows com 对话的一个包装类。
[DllImport("comdlg32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd);
第二,关于你的问题,我猜是最重要的: PrintDialog 类有这个例程,在 PrintDlg 调用关闭后调用
if (!UnsafeNativeMethods.PrintDlg(data))
return false;
IntSecurity.AllPrintingAndUnmanagedCode.Assert();
try {
UpdatePrinterSettings(data.hDevMode, data.hDevNames, data.nCopies, data.Flags, settings, PageSettings);
}
finally {
CodeAccessPermission.RevertAssert();
}
. . .
// VSWhidbey 93449: Due to the nature of PRINTDLGEX vs PRINTDLG, separate but similar methods
// are required for updating the settings from the structure utilized by the dialog.
// Take information from print dialog and put in PrinterSettings
private static void UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, short copies, int flags, PrinterSettings settings, PageSettings pageSettings) {
// Mode
settings.SetHdevmode(hDevMode);
settings.SetHdevnames(hDevNames);
if (pageSettings!= null)
pageSettings.SetHdevmode(hDevMode);
//Check for Copies == 1 since we might get the Right number of Copies from hdevMode.dmCopies...
//this is Native PrintDialogs
if (settings.Copies == 1)
settings.Copies = copies;
settings.PrintRange = (PrintRange) (flags & printRangeMask);
}
这里还有一个相当有趣的相互作用(记住您设置了 PrinterSettings.ToPage):
public PrinterSettings PrinterSettings {
get {
if (settings == null)
{
settings = new PrinterSettings();
}
return settings;
}
set {
if (value != PrinterSettings)
{
settings = value;
**printDocument = null;**
}
}
}
进而
public PrintDocument Document {
get { return printDocument;}
set {
printDocument = value;
**if (printDocument == null)
settings = new PrinterSettings();**
else
settings = printDocument.PrinterSettings;
}
}
我知道这不是一个直接的答案,但我认为应该为您指出为什么它不起作用的正确方向。在我看来,在对话的使用过程中,它可以愉快地取消更改设置,因为它将在完成时重新创建,但是当对话完成时,更改设置实际上会使文档打印设置无效,直到再次设置。可以手动执行此操作,或者它可能会被 M$ 以通常的内部/私有方式锁定在许多内部。
当然有一个选项(不是我知道的那么好)在调用之后直接使用 Win API - 如果需要,可以从上面的对话中提取代码来构建自己的包装器。
祝你好运。