【发布时间】:2013-07-19 00:42:10
【问题描述】:
以下代码在 Windows 7 上成功打印,但在 Windows XP 上无法运行。如果我进入记事本并手动打印文档,两台计算机的默认打印机设置都可以正常工作。在 Windows XP 机器上,它就在那里,没有错误,什么都没有。
如何调试它以获取错误消息或以其他方式找出为什么不打印?
try
{
if (File.Exists(pdfPath))
{
Process process = new Process();
process.StartInfo.FileName = pdfPath;
process.StartInfo.Verb = "print";
process.StartInfo.CreateNoWindow = true;
process.Start();
process.WaitForInputIdle();
process.Kill();
}
else
{
MessageBox.Show("The file \"" + pdfPath + "\" does not exist", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
statusLabel.Text = "";
return;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Unable to print packing slip", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
【问题讨论】:
-
输出窗口中是否显示任何内容?
-
我对 C# 很陌生,但我在目标计算机上的应用程序没有我知道的输出窗口。我有一个名为
statusLabel的状态栏,我手动更新它... -
输出窗口是 Visual Studio 中的诊断窗口; @Bob 表示在调试器中运行你的应用程序。
-
尝试添加
process.StartInfo.UseShellExecute = true。
标签: c#