我在選擇打印機打印文檔時遇到問題。進程始終默認打印文檔打印機
我的代碼是:
var filename = @"C:\Users\I\Desktop\test.doc";
PrintDialog pd = new PrintDialog();
pd.PrinterSettings =new PrinterSettings();
if (DialogResult.OK == pd.ShowDialog(this))
{
Process objP = new Process();
objP.StartInfo.FileName = filename;
objP.StartInfo.WindowStyle =
ProcessWindowStyle.Hidden; //Hide the window.
objP.StartInfo.Verb ="print";
objP.StartInfo.Arguments ="/p /h \"" + filename + "\" \"" + pd.PrinterSettings.PrinterName + "\"";
objP.StartInfo.CreateNoWindow = false;
//true;//!! Don't create a Window.
objP.Start();
//!! Start the process !!//
objP.CloseMainWindow();
}
,並不管我選擇,process
總是會使用默認的打印機,無論是什麼樣的pd.PrinterSettings.PrinterName
價值。
我的代碼有什麼問題?
「objP.StartInfo.Arguments」的值是否是您在執行此代碼時所期望的值?當你在命令提示符下手動鍵入時,它是否工作正常? –