【问题标题】:how to open program through C# program and give this program focus如何通过C#程序打开程序并赋予该程序焦点
【发布时间】:2009-11-15 14:37:36
【问题描述】:

如何通过C#程序(Windows Mobile)打开程序并赋予该程序焦点?

MarkJ 编辑:Gold 表示感谢 Process.Start 的建议,但由于某种原因,该程序仍然没有得到关注。

提前致谢, 黄金

【问题讨论】:

  • “关注这个项目”是指你的项目还是你刚刚启动的项目?
  • 您是否将原始应用程序中Form的TopMost属性设置为true?如果是这样,您启动的程序将不可见。

标签: c# .net focus


【解决方案1】:

您可以使用Process.Start(); 启动您的流程,然后:

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

public static bool BringWindowToTop(string windowName, bool wait)
{
      int hWnd = FindWindow(windowName, wait);
      if (hWnd != 0)
      {
           return SetForegroundWindow((IntPtr)hWnd);
      }
      return false;
}

找到窗口并把它带到前面

【讨论】:

    【解决方案2】:

    您可以通过调用Process.Start 来启动程序,如下所示:

    Process.Start(programPath);
    

    您也可以传入一个文件(例如,Word 文档),甚至是一个网站,它会自动在用户机器上该文件类型的默认程序中启动。

    当您调用Process.Start 时,程序应该会自动获得焦点。

    【讨论】:

    • Gold 表示程序已启动,但未获得焦点。 (在另一个问题中,现在已作为副本关闭)
    【解决方案3】:

    Process.Start()??

    【讨论】:

      【解决方案4】:

      使用下面的代码应该会自动将窗口放在顶部。

      Process.Start("path");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-05-19
        • 1970-01-01
        • 1970-01-01
        • 2020-09-11
        • 2010-11-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多