开发者

C# process start focus issue

When I start a new process, it automatically gets the focus. how can I prevent it from getting the focus or instead get back the focus to my application?

here is th开发者_如何学运维e code I'm using:

string path = @"c:\temp\myprocess.exe";  
ProcessStartInfo info = new ProcessStartInfo(path);  
info.WorkingDirectory = path;  
Process p = Process.Start(info);  

I just need the executed process not to get the focus.

Thank you very much,

Adi Barda


Maybe setting the WindowStyle property to Minimized can help.


If you don't need to show the process at all, try this:

string path = @"c:\temp\myprocess.exe";
ProcessStartInfo info = new ProcessStartInfo(path);
info.WorkingDirectory = path;
info.WindowStyle = ProcessWindowStyle.Hidden;

Or set WindowStyle to ProcessWindowStyle.Minimized if you want it visible but minimized, as Uwe Keim said.


can you do

myForm.Focus();

where myForm is the form on your main application


What i´ve done was to wait a little delay until the other application was succesfully loaded, then focus my application window.

//Test window
const string strCmdText = "/C cd C:\\sqlcipher";
Process.Start("CMD.exe", strCmdText);

//Delay
int liMilliseconds = 50;
Thread.Sleep(liMilliseconds);

//Code to bring window to front
this.WindowState = FormWindowState.Minimized;
this.Show();
this.WindowState = FormWindowState.Normal;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜