あなたの質問がなぜ投票に失敗したのか分かりません。
何とか私は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();
}
を閉じた後に呼び出され、このルーチンを持っている:あなたを参照して
[DllImport("comdlg32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd);
と第二、そして最も重要なのは、私は推測疑問。 。 。
// 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を使い分けるだけの選択肢があります。
幸運。
ダイアログを開く前に設定を変更しない理由はありますか? –
はい、私のアプリケーションでは、多くの異なる文書で構成された「マージされた文書」があります。印刷ダイアログでは、1つのドキュメントとして表示する必要がありますが、印刷するには個別に処理する必要があります。つまり、PrinterSettingsの中には、すべてのドキュメントを適用するものと、個々のドキュメントごとに個別に設定するものがあります。私は個々のプロパティ/設定私はユーザーの操作なしで計算することができますが、印刷のために私はそれらをプリンタの設定に注入する必要があります。 – user1182735
スニペットから実際の印刷ジョブにprinterSettingsオブジェクトがどのように適用されているかは完全にはわかりません。また、あなたのコードに欠けていることは、問題の原因を説明します。 –