PrintDialog显示在所有打开的窗口后面
问题描述:
我有一个简单的PrintDialog(代码如下)。我的应用程序是一个托盘应用程序,这意味着它没有窗口,只包含托盘图标中的几个简单的右键单击选项。给定一个文件路径,应用程序将打开一个打印对话框并让用户打印该项目。PrintDialog显示在所有打开的窗口后面
我看到以下问题......第一次打印时,对话框弹出到顶部,优先于所有其他打开的程序。在第一个之后,打印对话框总是在我打开的其他所有东西后面打开。例如,我在我的屏幕上打开了一个Web浏览器,打印对话框将在每次第一次打印后打开。
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() == DialogResult.OK)
{
ProcessStartInfo info = new ProcessStartInfo(filename);
info.Arguments = "\"" + pd.PrinterSettings.PrinterName + "\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.UseShellExecute = true;
info.Verb = "PrintTo";
try { Process.Start(info); }
catch (Exception e) {
// An exception occured while attempting to print
return false;
}
return true;
}
答
我能找到在这个岗位回答: Cannot show print dialog on the top of asp.net web control
离开这里的答案,因为我花了多天找到的东西,实际工作。希望这可以对别人有帮助。
//initialize a new window form
Form currentForm = new Form();
//show the form currentForm.Show();
Activate the form currentForm.Activate();
//Set its TopMost to true, so it will bring the form to the top
currentForm.TopMost = true;
//Set it to be Focus
currentForm.Focus()
//set the form.visible = false
currentForm.Visible = false;
//start to show the print dialog
printDialog.ShowDialog(currentForm)
//close the new form
currentForm.Close();
的可能重复[我怎样才能使一个过程窗口前?](https://stackoverflow.com/questions/18071381/how-can-i-bring-a-process-window-to -前方) – MethodMan