次の方法で共有


Control.ControlAccessibleObject.Owner プロパティ

ユーザー補助対象のオブジェクトの所有者を取得します。

Public ReadOnly Property Owner As Control
[C#]
public Control Owner {get;}
[C++]
public: __property Control* get_Owner();
[JScript]
public function get Owner() : Control;

プロパティ値

Control.ControlAccessibleObject を所有している Control

使用例

[Visual Basic, C#, C++] CheckBox クラスから派生したチェック ボックス コントロールを作成し、この派生したクラスで使用するカスタム Control.ControlAccessibleObject を作成する例を次に示します。派生クラス MyCheckBoxButtonAppearance を既定で持っているため、これはトグル ボタンとして表示されます。派生 Control.ControlAccessibleObject クラス MyCheckBoxControlAccessibleObject は、3 つのプロパティをオーバーライドして、表示の違いを考慮します。

 
Imports System
Imports System.Windows.Forms
Imports Accessibility
Imports System.Drawing

Namespace MyCustomControls
   Public Class MyCheckBox
      Inherits CheckBox
      
      Public Sub New()
         ' Make the check box appear like a toggle button.
         Me.Appearance = Appearance.Button
         ' Center the text on the button.
         Me.TextAlign = ContentAlignment.MiddleCenter
      End Sub
      
      ' Create an instance of the AccessibleObject 
      ' defined for the 'MyCheckBox' control 
      Protected Overrides Function CreateAccessibilityInstance() _
        As AccessibleObject
         Return New MyCheckBoxAccessibleObject(Me)
      End Function
   End Class
    
   ' Accessible object for use with the 'MyCheckBox' control.
   Friend Class MyCheckBoxAccessibleObject
      Inherits Control.ControlAccessibleObject
      
      Public Sub New(owner As MyCheckBox)
         MyBase.New(owner)
      End Sub
      
      Public Overrides ReadOnly Property DefaultAction() As String
         Get
            ' Return the DefaultAction based upon 
            ' the state of the control. 
            If CType(Owner, MyCheckBox).Checked Then
               Return "Toggle button up"
            Else
               Return "Toggle button down"
            End If
         End Get
      End Property
      
      Public Overrides Property Name() As String
         Get
            ' Return the Text property of the control 
            ' if the AccessibleName is null. 
            Dim accessibleName As String = Owner.AccessibleName
            If Not (accessibleName Is Nothing) Then
               Return accessibleName
            End If
            Return CType(Owner, MyCheckBox).Text
         End Get

         Set
            MyBase.Name = value
         End Set
      End Property
      
      Public Overrides ReadOnly Property Role() As AccessibleRole
         Get
            ' Since the check box appears like a button,
            ' make the Role the same as a button. 
            Return AccessibleRole.PushButton
         End Get
      End Property
   End Class
End Namespace

[C#] 
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;
         }
      }
   }
}

[C++] 
#using <mscorlib.dll>
#using <Accessibility.dll>
#using <System.Drawing.dll>
#using <System.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;

namespace MyCustomControls {
public __gc class MyCheckBox : public 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 = S"A toggle style button.";
   }

   // Create an instance of the AccessibleObject
   // defined for the 'MyCheckBox' control
protected:
   AccessibleObject* CreateAccessibilityInstance();
};

// Accessible Object* for use with the 'MyCheckBox' control.
private __gc class MyCheckBoxAccessibleObject : public Control::ControlAccessibleObject {
public:
   MyCheckBoxAccessibleObject(MyCheckBox* owner) : ControlAccessibleObject(owner) {
   }

   __property String* get_DefaultAction() {
      // Return the DefaultAction based upon
      // the state of the control.
      if ((dynamic_cast<MyCheckBox*>(Owner))->Checked) {
         return S"Toggle button up";
      } else {
         return S"Toggle button down";
      }
   }

   __property String* get_Name() {
      // Return the Text property of the control
      // if the AccessibleName is 0.
      String* name = Owner->AccessibleName;
      if (name != 0) {
         return name;
      }
      return (dynamic_cast<MyCheckBox*>(Owner))->Text;
   }
   __property void set_Name(String* value) {
      ControlAccessibleObject::set_Name(value);
   }

   __property AccessibleRole get_Role() {
      // Since the check box appears like a button,
      // make the Role the same as a button.
      return AccessibleRole::PushButton;
   }
};

AccessibleObject* MyCheckBox::CreateAccessibilityInstance() {
   return new MyCheckBoxAccessibleObject(this);
}
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Control.ControlAccessibleObject クラス | Control.ControlAccessibleObject メンバ | System.Windows.Forms 名前空間 | Parent | Control.ControlAccessibleObject