如何使用 UIAutomation 设置 MDI 子窗口的焦点 [英] How do I bring Set Focus of MDI Child Window using UIAutomation

查看:49
本文介绍了如何使用 UIAutomation 设置 MDI 子窗口的焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个旧的遗留应用程序需要自动化.它使用 MDI Windows.

We have an old legacy application we need to automate. It uses MDI Windows.

我们正在使用 UIAutomation 并且我可以成功地为每个 MDI 子窗口获取适当的 AutomationElement.我不能做的是把那个元素放在焦点上.

We're using UIAutomation and I can succesfully get the appropriate AutomationElement for each MDI Child window. What I cannot do is bring that element into focus.

这是我尝试过的一些示例代码,但失败了:

Here is some example code that I tried, that fails:

        var desktop = AutomationElement.RootElement;
        var dolphin = desktop.FindFirst(TreeScope.Children,
                new PropertyCondition(AutomationElement.NameProperty,
                    "Dolphin for Windows",
                    PropertyConditionFlags.IgnoreCase));
        dolphin.SetFocus();

        var workspace = dolphin.FindFirst(TreeScope.Children,
                new PropertyCondition(AutomationElement.NameProperty,
                    "Workspace",
                    PropertyConditionFlags.None));

        var childWindow = workspace.FindFirst(TreeScope.Children, new
                PropertyCondition(AutomationElement.NameProperty, "Sharp   "));
        childWindow.SetFocus();

此代码中的最后一行因 System.InvalidOperationException 而失败

The last line in this code fails with System.InvalidOperationException

实验中,我尝试在 childWindow 上找到一个控件,并在其上调用 SetFocus.它确实正确地将焦点设置在正确的控件上,但它没有将 MDI 窗口置于前台.

Experimenting, I tried finding a control on the childWindow, and calling SetFocus on it. It DID correctly set the focus on the right control, but it did not bring the MDI window to the foreground.

有什么想法吗?

推荐答案

在设置焦点之前,您是否尝试过BringToFront"?我可以想象顶级控件 (mdi-parent) 不允许关注孩子,或者当孩子 (mdi-child) 不可见时无法这样做.

Have you tried "BringToFront" before you set focus? I can imagine that the top-level control (mdi-parent) won't allow focus on children or is unable to do so when the child (mdi-child) when it's not visible.

这篇关于如何使用 UIAutomation 设置 MDI 子窗口的焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆