【问题标题】:VS2019 Community vb .net - type "AutomationElement" is not definedVS2019 Community vb .net - 类型“AutomationElement”未定义
【发布时间】:2021-09-06 05:15:29
【问题描述】:

我添加了对 UIAutomationTypes 和 UIAutomationClient 的引用 并使用这些导入

    Imports System.Windows.Automation
    Imports System.Runtime.InteropServices
    Imports System.Text

但我得到一个错误: 类型“AutomationElement”未定义 当我使用该代码时

 Dim rootElement As AutomationElement = AutomationElement.FromHandle(hwnd)

怎么了?

【问题讨论】:

标签: vb.net visual-studio-2019


【解决方案1】:

好的 我必须从文件中添加参考“UIAutomationClient”,而不是从参考管理器中选择

【讨论】:

    【解决方案2】:

    设置参考后

    • UIAutomationClient
    • UIAutomationCore
    • UIAutomationCoreRes

    所有在 uiautomationcore.dll 中你都可以在 vb .net 中做这样的事情

    Imports System
    
    Module Program
    
        Sub Main(args As String())
            Dim uiA As UIAutomationClient.CUIAutomation8 = New UIAutomationClient.CUIAutomation8
            Dim root As UIAutomationClient.IUIAutomationElement
    
            root = uiA.GetRootElement()
    
            Console.WriteLine("Hello World!" + root.CurrentClassName)
        End Sub
    End Module
    

    在c#中是完整的例子

        using System;
    
    namespace ConsoleApp3
    {
        class Program
        {
            static void Main(string[] args)
            {
                UIAutomationClient.CUIAutomation8 uia = new UIAutomationClient.CUIAutomation8();
                UIAutomationClient.IUIAutomationElement root;
    
                root = uia.GetRootElement();
    
                Console.WriteLine("Hello World!" + root.CurrentClassName);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2011-08-15
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多