mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

UIAutomation学习

Posted on 2010-01-18 18:24  mrfangzheng  阅读(328)  评论(0编辑  收藏  举报
  1. 在另一线程中执行Find等操作
    代码
    IntPtr handle = frm.Handle;

    Action act = () =>
    {
        UIAutomationMapping mapping = new UIAutomationMapping(handle);

        
    foreach (AutomationElement item in mapping.CheckedListBoxColumnNamesRows)
        {
            item.SetFocus();
            SendKeys.SendWait(" ");  // Send a {SPACE} to check the checkbox. 
        }

        InvokePattern aeOkButtonClick = (InvokePattern)mapping.ButtonOk.GetCurrentPattern(InvokePattern.Pattern);
        aeOkButtonClick.Invoke();
    };

    act.BeginInvoke(nullnull);
  2. 查找列表:
    this.CheckedListBoxColumnNames.FindAll(TreeScope.Descendants,
                        new PropertyCondition(
                            AutomationElement.ControlTypeProperty,
                            ControlType.ListItem));
  3. TogglePattern似乎对CheckListBox不起作用, 可用如下代码代替:
    item.SetFocus();
    SendKeys.SendWait(" ");  // Send a {SPACE} to check the checkbox.