public static void TabSelect(IntPtr controlHandle, int index) { try { AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle); AutomationElementCollection aec = SelectionItemPatternHelper.GetListItems(control); /* When using the GetListItems() methods, item index 0 is the tab control itself, so add on to get to correct TabItem */ if (index >= int.MaxValue) { throw new ProdOperationException("input must be less than Int32.MaxValue"); } int adjustedIndex = index + 1; string itemText = aec[adjustedIndex].Current.Name; StaticEvents.RegisterEvent(SelectionItemPattern.ElementSelectedEvent, control); SelectionItemPatternHelper.SelectItem(SelectionItemPatternHelper.FindItemByText(control, itemText)); LogController.ReceiveLogMessage(new LogMessage(control.Current.Name)); } catch (InvalidOperationException) { /* Call native function */ ProdTabNative.SetSelectedTab(controlHandle, index); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
/// <summary> /// Gets the number of child tabs contained in the tab control /// </summary> /// <param name="controlHandle">The target controls handle.</param> /// <returns> /// The number of tabs in a TabControl /// </returns> /// <exception cref="ProdOperationException">Examine inner exception</exception> public static int TabGetCount(IntPtr controlHandle) { try { AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle); int retVal = SelectionItemPatternHelper.GetListItemCount(control); if (retVal == -1) { ProdTabNative.GetTabCount(controlHandle); } LogController.ReceiveLogMessage(new LogMessage(retVal.ToString(CultureInfo.CurrentCulture))); return(retVal); } catch (InvalidOperationException err) { throw new ProdOperationException(err.Message, err); } catch (ElementNotAvailableException err) { throw new ProdOperationException(err.Message, err); } catch (ArgumentException err) { throw new ProdOperationException(err.Message, err); } }
private static int NativeGetItemCount(BaseProdControl control) { if (control.UIAElement.Current.ControlType == ControlType.Tab) { return(ProdTabNative.GetTabCount((IntPtr)control.UIAElement.Current.NativeWindowHandle)); } if (control.UIAElement.Current.ControlType == ControlType.ComboBox) { ProdComboBoxNative.GetItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle); } return(ProdListBoxNative.GetItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle)); }
private static bool NativeIsItemSelected(BaseProdControl control, int index) { int selectedIndex; if (control.UIAElement.Current.ControlType == ControlType.ComboBox) { selectedIndex = ProdComboBoxNative.GetSelectedIndexNative((IntPtr)control.UIAElement.Current.NativeWindowHandle); } else { selectedIndex = ProdTabNative.GetSelectedTab((IntPtr)control.UIAElement.Current.NativeWindowHandle); } return(selectedIndex == index); }