Exemplo n.º 1
0
        private static void checkboxAction(AutomationElement ae, ToggleState ts)
        {
            TogglePattern pattern;

            pattern = ae.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
            TogglePattern.TogglePatternInformation tpi = pattern.Current;
            if (tpi.ToggleState != ts)
            {
                pattern.Toggle();
            }
        }
Exemplo n.º 2
0
        private static string CheckboxToggleOnOff(string wName, string cName, ToggleState ts, bool isPartContainCheckedListItemName)
        {
            ControlOp     co   = new ControlOp(cName, ControlType.ListItem);
            List <IntPtr> hWnd = co.GetChildWindow(wName);

            if (hWnd.Count != 0)
            {
                for (int i = hWnd.Count - 1; i >= 0; i--)
                {
                    AutomationElementCollection aec = co.FindByMultipleConditions(AutomationElement.FromHandle(hWnd[i]));
                    foreach (AutomationElement ae in aec)
                    {
                        if (isPartContainCheckedListItemName)
                        {
                            if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString().Contains(cName))
                            {
                                TogglePattern pattern;
                                pattern = ae.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
                                TogglePattern.TogglePatternInformation tpi = pattern.Current;
                                if (tpi.ToggleState != ts)
                                {
                                    pattern.Toggle();
                                }
                                return("Done");
                            }
                        }
                        else
                        {
                            if (ae.GetCurrentPropertyValue(AutomationElement.NameProperty).ToString() == cName)
                            {
                                TogglePattern pattern;
                                pattern = ae.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;
                                TogglePattern.TogglePatternInformation tpi = pattern.Current;
                                if (tpi.ToggleState != ts)
                                {
                                    pattern.Toggle();
                                }
                                return("Done");
                            }
                        }
                    }
                }
            }
            else
            {
                return("ListItem not found");
            }
            return("ListItem not found");
        }