PrintDialogが表示された後にプリンタセットを変更しました
-
14-12-2019 - |
質問
ダイアログが表示された後、system.windows.forms.printDialogから取得したSystem.Drawing.PrinterSettingsオブジェクトを変更しようとしています。 PrinterSettingsオブジェクトのプロパティ値を変更することはできますが、ドキュメントを印刷すると、ダイアログが表示された後に作成した変更のどれも実際に考慮されません。
これは私が意味するものの例です:
//Show the printdialog and retreive the printersettings
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() != DialogResult.OK)
return;
var printerSettings = printDialog.PrinterSettings;
//Now modify the printersettings object
printerSettings.ToPage = 8;
.
印刷用のPrinterSettingsオブジェクトを使用します。私は言葉を印刷する必要があるので、私はこれのために3番手のDLL aspose.words.wordsを使いますが、これは問題にならないようです。ダイアログが表示された後、すべての設定はすでにプリンタにコミットされており、プリンタセッティングを変更しています。これを働かせる方法についてのアイデアはどれでもありますか?
編集:これにはいくつかの回避策があります。私がここに欲しいものは、これらの具体的な質問に対する答えを得ることです:ダイアログが表示された後にPrinterSettingsオブジェクトを変更することが可能であり、印刷時に考慮されます。誰かがこれがどのように機能できるかを1つだけ知っている場合(あなたが印刷に使用したいAPIを決定することができます、PrinterSettingsオブジェクトが使用されている限り、それは問題は関係ありません)
解決
なぜあなたの質問がダウン投票をしたのかわからない、私にとってかなり合理的に見えますか????
とにかく、私がPrintDialogで気づいたいくつかのこと(あなたの質問に答えるかもしれません)。
最初のことは、それがWindows COMダイアログのための単なるラッパークラスであることです。
[DllImport("comdlg32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd);
.
と2番目の、そしてあなたを参照して最も重要な質問私は推測します: PrintDialogクラスには、PrintDLG Call
のクローズ後に呼び出されるこのルーチンがあります。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;
}
}
.
直接の答えではないが、私はそれが機能していない理由の正しい方向にあなたを指すべきだと思います。対話の使用中は、完了時に再作成されるため、変更の設定を喜んで無効にすることができますが、ダイアログが完了したら、設定を変更すると、再度設定されるまで文書印刷設定が無効になります。これを手動で行うことが可能かもしれません、あるいは通常の内部/秘密の方法では多くの内部の内部/秘密の方法では、
コールコードが上記のダイアログからヒットされた後にwin apiを使用するだけで、必要に応じてあなた自身のラッパーを構築することができるようにするだけで、win apiを使用することができます。
頑張ってください。
他のヒント
アスペースマニュアルから:
AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
.
だからあなたが印刷しようとしている単語文書にYuor Modified PrinterSettingsオブジェクトを渡すことができます。これがうまくいくかどうか教えてもらえますか。