我创建了一个exe并将在新线程中提示打印对话框。 当用户点击其他应用程序中的按钮时,将运行此exe。如何在打印对话框关闭之前将打印对话框置于最顶层或不允许用户切换回调用者?感谢。
Thread t = new Thread(() =>
{
System.Windows.Controls.PrintDialog pDialog = new System.Windows.Controls.PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
Nullable<Boolean> print = pDialog.ShowDialog();
if (print == true)
{
}
});
t.SetApartmentState(ApartmentState.STA);
t.Start();
答案 0 :(得分:0)
`[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd,
int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
private const int HWND_TOPMOST = -1;
private const int HWND_NOTOPMOST = -2;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_SHOWWINDOW = 0x0040;
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string lclassName, string windowTitle);
private bool TweakPrintDialog()
{
IntPtr result = IntPtr.Zero;
IntPtr printDialogHandle = FindWindowEx(<Insert here Current WindowHandler>, result, "#32770", null);
if (printDialogHandle != IntPtr.Zero)
{
SetWindowPos(printDialogHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
return false;
}
return true;
}
` 使用:
Dispatcher.BeginInvoke(new Action(() =>
{
do
{
Thread.Sleep(100);
} while (TweakPrintDialog());
}));
if (printDialog.ShowDialog() == true)
{