Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AccessibleObject implementation for custom controls

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

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());
    }
}

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 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
{        
}

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:

UIVerify Snapshot

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;
}

I can see a node on the UIVerify:

enter image description here

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

Why are not my controls on the tree?

I do not know what I am missing.

like image 830
Juan María Laó Avatar asked Apr 04 '16 06:04

Juan María Laó


Video Answer


1 Answers

Override Name,value,Role in AccessibleForm class

like image 79
user2082630 Avatar answered Sep 28 '22 19:09

user2082630