小编Coc*_*tec的帖子

C#System.Windows.Automation获取元素文本

我试图从C#中的Automation实现应用程序控件的文本/标签.

到目前为止,我能够使用此函数获取AutomationElement应用程序树(例如记事本):

    private void WalkControlElements(AutomationElement rootElement, TreeNode treeNode)
    {
        AutomationElement elementNode = TreeWalker.ContentViewWalker.GetFirstChild(rootElement);;

        while (elementNode != null)
        {
            TreeNode childTreeNode = treeNode.Nodes.Add(elementNode.Current.ControlType.LocalizedControlType);

            // here I want to get text from 'elementNode'

            WalkControlElements(elementNode, childTreeNode);
            elementNode = TreeWalker.ControlViewWalker.GetNextSibling(elementNode);
        }
    }
Run Code Online (Sandbox Code Playgroud)

我试着按照这篇文章http://msdn.microsoft.com/en-us/library/ms788751(v=vs.110).aspx但它只能获得文本属性作为字体名称,字体粗细等.

有人能指出正确的程序如何使用Automation获取元素文本?

c# ui-automation

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

ui-automation ×1