Control.ControlAccessibleObject.Owner, propriété
Mise à jour : novembre 2007
Obtient le propriétaire de l'objet accessible.
Assembly : System.Windows.Forms (dans System.Windows.Forms.dll)
/** @property */ public Control get_Owner()
public function get Owner () : Control
Valeur de propriété
Type : System.Windows.Forms.ControlControl possédant Control.ControlAccessibleObject.
L'exemple de code suivant crée un contrôle Check Box qui dérive de la classe CheckBox, ainsi qu'un Control.ControlAccessibleObject personnalisé pour la classe dérivée à utiliser. La classe dérivée MyCheckBox possède un Appearance de Button par défaut, par conséquent elle s'affiche sous forme de bouton bascule. La classe Control.ControlAccessibleObject dérivée, MyCheckBoxControlAccessibleObject, substitue trois propriétés pour tenir compte de la différence d'aspect.
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; } } } }
package MyCustomControls;
import System.*;
import System.Windows.Forms.*;
import Accessibility.*;
import System.Drawing.*;
public class MyCheckBox extends CheckBox
{
public MyCheckBox()
{
// Make the check box appear like a toggle button.
this.set_Appearance(get_Appearance().Button);
// Center the text on the button.
this.set_TextAlign(ContentAlignment.MiddleCenter);
// Set the AccessibleDescription text.
this.set_AccessibleDescription("A toggle style button.");
} //MyCheckBox
// Create an instance of the AccessibleObject
// defined for the 'MyCheckBox' control
protected AccessibleObject CreateAccessibilityInstance()
{
return new MyCheckBoxAccessibleObject(this);
} //CreateAccessibilityInstance
} //MyCheckBox
// Accessible object for use with the 'MyCheckBox' control.
class MyCheckBoxAccessibleObject extends Control.ControlAccessibleObject
{
public MyCheckBoxAccessibleObject(MyCheckBox owner)
{
super(owner);
} //MyCheckBoxAccessibleObject
/** @property
*/
public String get_DefaultAction()
{
// Return the DefaultAction based upon
// the state of the control.
if (((MyCheckBox)get_Owner()).get_Checked()) {
return "Toggle button up";
}
else {
return "Toggle button down";
}
} //get_DefaultAction
/** @property
*/
public String get_Name()
{
// Return the Text property of the control
// if the AccessibleName is null.
String name = get_Owner().get_AccessibleName();
if (name != null) {
return name;
}
return ((MyCheckBox)get_Owner()).get_Text();
} //get_Name
/** @property
*/
public void set_Name(String value)
{
super.set_Name(value);
} //set_Name
/** @property
*/
public AccessibleRole get_Role()
{
// Since the check box appears like a button,
// make the Role the same as a button.
return AccessibleRole.PushButton;
} //get_Role
} //MyCheckBoxAccessibleObject
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.