开发者

How do I bring Set Focus of MDI Child Window using UIAutomation

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

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();

The last line in this code fails with System.InvalidOperationException

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.

Any ideas?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜