none
UI Automation Issue: the Tab Control does not detect the Tab change. RRS feed

  • Question

  • Hi All,

    First at all, I tried to use some Events but that will not work for me, I mean... the UI Automation feature takes a VERY LONG time to detect the events like:

    Automation.AddAutomationEventHandler(
                            SelectionItemPattern.ElementSelectedEvent,
                            tabElement,
                            TreeScope.Element | TreeScope.Descendants,
                            new AutomationEventHandler(TargetSelectionHandler));

    private void TargetSelectionHandler(object src, AutomationEventArgs e)
            {
                AutomationElement sourceItem = src as AutomationElement;
                Console.WriteLine("Item {0} is selected.", sourceItem.Current.Name);
            }


    I'm not interested on that way to solve the problem I have... let me explain you the problem and let me know what you think :-)

    1) I have a small ( test ) application, is only a Windows.Forms which contains only one Tab Control with 5 tabs ( each tab contains some controls like labels, textFields, checkBoxes, etc )...

    2) I have a Thread which is checking for a change in focus... in other words, I'm reviewing each 2 secs if the control in-focus has changed or not.. That's easy, I'm using the (IntPtr) wHnd of the in-focus control and creating an instance of the AutomationElement object each time,...   _window = AutomationElement.FromHandle( hwnd ); 

    3) The desciption of problem that I'm having is:

    a. My small app, called colors starts and my "Colors" screen appears.
    b. If I click on the "Blue" Tab, the focus change is detected, UIAutoElement.Current.AutomationId = m_tabCtrl_m_tabpageBlue
    c. Click on the "Red" Tab. focus change is not detected.
    d. Click on the "Black" Tab. focus change is not detected.
    e. click on the "Yellow" tab. focus change is not detected.
    f. but If I click on some field within any tab, the focus change is detected again...

    Questions.
    - There's a way to detect that the tab has changed If I have the Control's wHnd.. and I already know that the control is a TabControl ??
    - if not, the Automation object has some property or something where I can get the Tab that is currently selected ?

    I really appreciate your help.

    Thanks,
    Best regards.
    Saturday, October 31, 2009 4:09 PM