Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Custom WinForms Control Work with Narrator (Accessibility)

I have a custom list control derived from Control class.

I need to make it accessible to people with disabilities through MSAA (Microsoft Active Accessibility).

So far I understand that I need to create class that inherits from ControlAccessibleObject and then return its instance in Control.CreateAccessibilityInstance method override.

The problem is that I have implemented this and it seems not work with Windows Narrator tool.

For example, when I click on an item in standard ListView, the Narrator speaks out the selected item text.

But when I click on item in my control, nothing happens (although the item text is requested in my ControlAccessibleObject implementation)

I thought I need to implement IAccessible as well, but I looked on .NET refrence source code and the ListView does not implement this interface. I thought maybe this is implemented in the wrapped Win32 control, so I took a look on similar control - DataGridView - but this does not implement IAccessible as well.

DataGridView have accessibility support, but although I copied all the important code of DataGridViewAccessibleObject, it still does not work in my control.

Do anyone have more experience with custom control accessibility in WinForms?

like image 595
Libor Avatar asked May 21 '26 01:05

Libor


1 Answers

Okay, I found it: The Control.AccessibilityNotifyClients method does the magic. One have to override this method in a derived control.

However, to make screen readers speak the text, I had to call:

AccessibilityNotifyClients(AccessibleEvents.Focus, index);
AccessibilityNotifyClients(AccessibleEvents.Selection, index);

Here the index is an index of newly selected item.

I found this code in the .NET reference source of CheckedListBox. When I used Focus or Selection event solely, the screen reader have not reacted. The spoken text also depend on the AccessibleObject state that corresponds to a newly selected item.

like image 174
Libor Avatar answered May 26 '26 03:05

Libor