您的位置:首页 > 博客中心 > 电脑问题 >

winform恢复窗口前端显示

时间:2022-03-18 07:54

1.添加系统DLL引用

[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

2.得到窗口句柄

应用程序运行时

Process instance = null;
Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); //遍历与当前进程名称相同的进程列表 foreach (Process process in processes) {   //如果实例已经存在则忽略当前进程   if (process.Id != current.Id)   {     //得到已经存在的进程     instance = process;
    break;
  }
}

应用程序运行中

Process instance = Process.GetCurrentProcess();

3.调用API

SwitchToThisWindow(instance.MainWindowHandle, true);

 

热门排行

今日推荐

热门手游