Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Control.ControlAccessibleObject Constructor

Initializes a new instance of the Control.ControlAccessibleObject class.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public ControlAccessibleObject(
	Control ownerControl
)

Parameters

ownerControl
Type: System.Windows.Forms.Control

The Control that owns the Control.ControlAccessibleObject.

ExceptionCondition
ArgumentNullException

The ownerControl parameter value is null.

The following code example creates a check box control that derives from the CheckBox class and creates a custom Control.ControlAccessibleObject for the derived class to use. The derived class, MyCheckBox, has an Appearance of Button by default so it appears as a toggle button. The derived Control.ControlAccessibleObject class, MyCheckBoxControlAccessibleObject, overrides three properties to account for the difference in appearance.

using System;
using System.Windows.Forms;
using Accessibility;
using System.Drawing;

namespace MyCustomControls
{
   public class MyCheckBox : CheckBox
   {
      public MyCheckBox()
      {
         // Make the check box appear like a toggle button. 
         this.Appearance = Appearance.Button;
         // Center the text on the button. 
         this.TextAlign = ContentAlignment.MiddleCenter;
	 // Set the AccessibleDescription text. 
         this.AccessibleDescription = "A toggle style button.";
      }

      // Create an instance of the AccessibleObject  
      // defined for the 'MyCheckBox' control 
      protected override AccessibleObject CreateAccessibilityInstance() 
      {
         return new MyCheckBoxAccessibleObject(this);
      }
   }

   // Accessible object for use with the 'MyCheckBox' control. 
   internal class MyCheckBoxAccessibleObject : Control.ControlAccessibleObject 
   {
      public MyCheckBoxAccessibleObject(MyCheckBox owner) : base(owner) 
      {

      }

      public override string DefaultAction 
      {
         get
         {
            // Return the DefaultAction based upon  
            // the state of the control. 
            if( ((MyCheckBox)Owner).Checked )
            {
               return "Toggle button up";
            }
            else
            {
               return "Toggle button down";
            }
         }
      }

      public override string Name 
      {
         get 
         {
            // Return the Text property of the control  
            // if the AccessibleName is null. 
            string name = Owner.AccessibleName;
            if (name != null) 
            {
               return name;
            }
            return ((MyCheckBox)Owner).Text;
         }

         set
         {
            base.Name = value;
         }
      }            

      public override AccessibleRole Role 
      {
         get 
         {
            // Since the check box appears like a button, 
            // make the Role the same as a button. 
            return AccessibleRole.PushButton;
         }
      }
   }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft