【发布时间】:2012-09-02 16:17:57
【问题描述】:
我想将 windows 窗体显示为一个弹出窗口,出现在所有打开的其他应用程序窗口的顶部
我使用了Focus 方法,但它没有用。
所以我试过了:
using System.Diagnostics;
using System.Runtime.InteropServices;
// Sets the window to be foreground
[DllImport("User32")]
private static extern int SetForegroundWindow(IntPtr hwnd);
// Activate or minimize a window
[DllImportAttribute("User32.DLL")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_RESTORE = 9;
private void ActivateApplication(string briefAppName)
{
Process[] procList = Process.GetProcessesByName(briefAppName);
if (procList.Length > 0)
{
ShowWindow(procList[0].MainWindowHandle, SW_RESTORE);
SetForegroundWindow(procList[0].MainWindowHandle);
}
}
如上一个关于 SO Here 的问题所述
但我无法使用它。
正确答案海报说“Basically, call ShowWindow() then SetForegroundWindow().”但我不知道这些方法的参数是什么
我究竟应该将什么传递给ShowWindow(); 和 SetForegroundWindow();方法??
有什么帮助吗?
【问题讨论】:
标签: c# winforms forms show-hide