【问题标题】:Bring Windows Mobile 6 forms into the front将 Windows Mobile 6 表单置于最前面
【发布时间】:2010-09-21 18:41:18
【问题描述】:

我在将 windows mobile 6 窗体放在前面时遇到问题。 我已经尝试过这样的事情

Form1 testForm = new Form1();
testForm.Show();
testForm.BringToFront();
testForm.Focus();

但它总是在包含该代码的表单后面。 唯一对我有用的是

testForm.TopMost = true;

或隐藏();旧表格,然后显示新表格,但我想避免隐藏另一种表格。无论如何,TopMost 使用多种其他形式并不是很干净。

另一件事是

testForm.ShowDialog();

但我不想显示表单模式。

简短地说。我只想在另一个表单前面显示新表单,如果我关闭它,我想再次看到旧表单。

也许有人可以帮助我解决这个问题。谢谢。

【问题讨论】:

    标签: c# winforms windows-mobile


    【解决方案1】:

    我没有在WM6中尝试过,但是你可以使用一些pinvoke来调用Win32函数:

    [DllImport("coredll.dll")]
    private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
    [DllImport("coredll.dll", EntryPoint="SetForegroundWindow")]
    private static extern int SetForegroundWindow(IntPtr hWnd);
    

    调用 FindWindow 获取句柄,然后调用 SetForegroundWindow。您可能会发现有用的其他功能:

    ShowWindow、BringWindowToTop、SetWindowPos

    【讨论】:

      【解决方案2】:

      试试这个:

      在表单上设置一个计时器。
      将其设置为短时间,例如 100 毫秒。
      在 timer_Tick 事件中
      - 禁用计时器(这样它就不会再次滴答作响)然后
      - 加载子窗体。

      您可能还想查看form.owner 属性:
      "当一个窗体被另一个窗体拥有时,它被最小化并与所有者窗体一起关闭。例如,如果 Form2 由窗体 Form1 拥有,如果 Form1 被关闭或最小化,则 Form2 也被关闭或最小化。 em> 拥有的表单也永远不会显示在其拥有者表单的后面。”

      【讨论】:

        猜你喜欢
        • 2012-10-07
        • 2011-05-19
        • 1970-01-01
        • 1970-01-01
        • 2012-01-02
        • 1970-01-01
        • 2020-04-26
        • 2011-02-06
        • 2015-05-03
        相关资源
        最近更新 更多