Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#将非关联应用程序带到前台_C#_Foreground - Fatal编程技术网

C#将非关联应用程序带到前台

C#将非关联应用程序带到前台,c#,foreground,C#,Foreground,我一直在网上搜索答案,以便把一个程序放到前台。我一直在用SendKeys发送alt-tab键,以贫民窟的方式来做这件事。我试过了,但没用 private void execute() { setApp("League of Legends.exe"); Thread.Sleep(1500); } [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr hWnd); private stati

我一直在网上搜索答案,以便把一个程序放到前台。我一直在用SendKeys发送alt-tab键,以贫民窟的方式来做这件事。我试过了,但没用

private void execute()
{
    setApp("League of Legends.exe");
    Thread.Sleep(1500);
}

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static void setApp(String filename)
{
    Process[] SameProcesses = Process.GetProcessesByName(filename);
    Process SameProcess = SameProcesses[0];
    if (SameProcess.Equals(null))
    {
        System.Windows.Forms.MessageBox.Show("No process");
    }
    else
    { 
        SetForegroundWindow(SameProcess.MainWindowHandle); 
    }
}

什么不起作用?你看到消息框了吗?也许你可以在这里找到更多信息不,消息框没有出现