2017-10-16 17 views
0

私は単純な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; 
} 
+0

可能性のある重複した[私が前にプロセスウィンドウをもたらすことができる方法は?](https://stackoverflow.com/questions/18071381/how-can-i-bring-a-process-window-to - フロント) – MethodMan

答えて

0

私はこの記事で答えを見つけることができました: 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(); 
関連する問題