用于自定义控件的AccessibleObject实现 [英] AccessibleObject implementation for custom controls

查看:102
本文介绍了用于自定义控件的AccessibleObject实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Windows窗体控件库,在实现可访问性时遇到问题。

I have a very simple controls library for Windows Forms and I am getting problems to implement accessibility.

我有一个非常简单的Form,其成员包含我的库的控件列表,并且我重写了CreateAccessibilityInstance:

I have a very simple Form with a member that contains a list of controls of my library, and I have overriden the CreateAccessibilityInstance:

public partial class Form1 : Form
{
    protected override AccessibleObject CreateAccessibilityInstance()
    {
        return new AccessibleForm(this);
    }

    public MyContainer MyContainer;

    public Form1()
    {
        InitializeComponent();
        MyContainer = new MyContainer();
        MyContainer.Controls.Add(new MyButton());
    }
}

AccessibleForm类如下:

The AccessibleForm class looks like:

public class AccessibleForm: Control.ControlAccessibleObject
{
    private Form1 form1;

    public AccessibleForm(Form1 owner):base(owner)
    {
        this.form1 = owner;
    }

    public override AccessibleObject GetChild(int index)
    {
        return this.form1.MyContainer.Controls[index].AccessibilityObject;
    }

    public override int GetChildCount()
    {
        return this.form1.MyContainer.Controls.Count() ;
    }
}

MyContanier和MyButton类继承自BaseControl,它们非常简单:

MyContanier and MyButton classes inherits from BaseControl, they are very easy:

public class BaseControl : Control
{
    protected override AccessibleObject CreateAccessibilityInstance()
    {
        return new AccessibleObject();
    }
}


public class MyContainer:BaseControl
{
    public List<BaseControl> Controls { get; set; }

    public MyContainer()
    {
        this.Controls = new List<BaseControl>();
    }
}

public class MyButton:BaseControl
{        
}

重点是,当我运行UIVerify工具查看控件是否生成正确的结构时,我看不到它们:

The point is that when I run the UIVerify tool to see if my controls are generating the correct structure I can not see them:

另一点是,如果我以这种方式修改AccessibleForm类的GetChild方法:

Another point is, that if I modify the GetChild method from AccessibleForm class in this way:

public override AccessibleObject GetChild(int index)
{
    return new AccessibleObject();
    ////return this.form1.MyContainer.Controls[index].AccessibilityObject;
}

我可以在UIVerify上看到一个节点:

I can see a node on the UIVerify:

但是修改GetChild方法以返回自定义可访问对象不会显示任何内容。

But modifying the GetChild method to return a custom accessible object it shows me nothing.

为什么我的控件不在树上?

Why are not my controls on the tree?

我不知道自己缺少什么。 p>

I do not know what I am missing.

推荐答案

覆盖AccessibleForm类中的名称,值,作用

Override Name,value,Role in AccessibleForm class

这篇关于用于自定义控件的AccessibleObject实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆