不知道爲什麼你的問題得到了否決票,對我來說看起來相當合理?無論如何,我已經注意到了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 $以許多內部通常的內部/私有方式執行的。
當然還有一種選擇(不是很好,我知道)只使用運API調用後diectly - 代碼可以從上面的dialgues被hythed如果需要建立自己的包裝。
祝你好運。
在打開對話框之前沒有更改設置的任何原因? – 2012-03-14 15:14:27
是的,在我的應用程序中,我有「合併文檔」,它由許多不同的文檔組成。在打印對話框中,它們應該顯示爲一個文檔,但是對於打印,我需要單獨處理它們。更確切地說:一些PrinterSettings應該適用於所有文檔,其他我需要爲每個文檔單獨設置。我可以在沒有用戶交互的情況下計算出各個屬性/設置,但對於打印,我需要將這些屬性注入打印機設置。 – user1182735 2012-03-14 15:19:57
從代碼片段中完全不清楚printerSettings對象如何應用於實際的打印作業。代碼中缺少的內容也解釋了問題的原因。 – 2012-03-14 15:30:10