Cette documentation est archivée et n’est pas conservée.

IExtenderProviderService, interface

Fournit une interface pour l'ajout et la suppression de fournisseurs d'extendeurs au moment du design.

Espace de noms : System.ComponentModel.Design
Assembly : System (dans system.dll)

public interface IExtenderProviderService
public interface IExtenderProviderService
public interface IExtenderProviderService

Généralement, seuls les composants qui ont été ajoutés à un conteneur proposent des fournisseurs d'extendeurs. IExtenderProviderService vous permet d'étendre cette fonctionnalité aux objets qui ne se trouvent pas dans le conteneur.

L'exemple suivant montre comment utiliser IExtenderProviderService à partir d'un concepteur pour ajouter ou supprimer une implémentation de IExtenderProvider.

using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace ExtenderServiceExample
{    
    // This designer adds a ComponentExtender extender provider, 
    // and removes it when the designer is destroyed.
    public class ExtenderServiceDesigner : System.Windows.Forms.Design.ControlDesigner
    {
        // A local reference to an obtained IExtenderProviderService.
        private IExtenderProviderService localExtenderServiceReference;
        // An IExtenderProvider that this designer supplies.
        private ComponentExtender extender;
        
        public ExtenderServiceDesigner()
        {
        }

        public override void Initialize(System.ComponentModel.IComponent component)
        {
            base.Initialize(component);

            // Attempts to obtain an IExtenderProviderService.
            IExtenderProviderService extenderService = (IExtenderProviderService)component.Site.GetService(typeof(IExtenderProviderService));
            if( extenderService != null )
            {
                // If the service was obtained, adds a ComponentExtender 
                // that adds an "ExtenderIndex" integer property to the 
                // designer's component.
                extender = new ComponentExtender();                
                extenderService.AddExtenderProvider( extender );
                localExtenderServiceReference = extenderService;
            }
            else
                MessageBox.Show("Could not obtain an IExtenderProviderService.");
        }

        protected override void Dispose(bool disposing)
        {
            // Removes any previously added extender provider.
            if( localExtenderServiceReference != null )
            {
                localExtenderServiceReference.RemoveExtenderProvider( extender );
                localExtenderServiceReference = null;
            }            
        }
    }
    
    // IExtenderProviderImplementation that adds an integer property 
    // named "ExtenderIndex" to any design-mode document object.
    [ProvidePropertyAttribute("ExtenderIndex", typeof(IComponent))]
    public class ComponentExtender : System.ComponentModel.IExtenderProvider
    {
        // Stores the value of the property to extend a component with.
        public int index = 0;        
    
        public ComponentExtender()
        {
        }

        public bool CanExtend(object extendee)
        {         
            // Extends any type of object.
            return true;
        }

        public int GetExtenderIndex(IComponent component)
        {
            return index;
        }

        public void SetExtenderIndex(IComponent component, int index)
        {
            this.index = index;
        }
    }

    // Example UserControl associated with the ExtenderServiceDesigner.
    [DesignerAttribute(typeof(ExtenderServiceDesigner))]
    public class ExtenderServiceTestControl : System.Windows.Forms.UserControl
    {		
        public ExtenderServiceTestControl()
        {						
        }
    }
}

package ExtenderServiceExample;
import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;

// This designer adds a ComponentExtender extender provider, 
// and removes it when the designer is destroyed.
public class ExtenderServiceDesigner extends 
    System.Windows.Forms.Design.ControlDesigner
{
    // A local reference to an obtained IExtenderProviderService.
    private IExtenderProviderService localExtenderServiceReference;

    // An IExtenderProvider that this designer supplies.
    private ComponentExtender extender;

    public ExtenderServiceDesigner()
    {
    } //ExtenderServiceDesigner

    public void Initialize(System.ComponentModel.IComponent component)
    {
        super.Initialize(component);

        // Attempts to obtain an IExtenderProviderService.
        IExtenderProviderService extenderService = (IExtenderProviderService)
            component.get_Site().GetService(IExtenderProviderService.class.
            ToType());
        if (extenderService != null) {
            // If the service was obtained, adds a ComponentExtender 
            // that adds an "ExtenderIndex" integer property to the 
            // designer's component.
            extender = new ComponentExtender();
            extenderService.AddExtenderProvider(extender);
            localExtenderServiceReference = extenderService;
        }
        else {
            MessageBox.Show("Could not obtain an IExtenderProviderService.");
        }
    } //Initialize

    protected void Dispose(boolean disposing)
    {
        // Removes any previously added extender provider.
        if (localExtenderServiceReference != null) {
            localExtenderServiceReference.RemoveExtenderProvider(extender);
            localExtenderServiceReference = null;
        }
    } //Dispose
} //ExtenderServiceDesigner

// IExtenderProviderImplementation that adds an integer property 
// named "ExtenderIndex" to any design-mode document object.
/** @ attribute ProvidePropertyAttribute("ExtenderIndex", 
    IComponent.class.ToType())
 */
public class ComponentExtender implements 
    System.ComponentModel.IExtenderProvider
{
    // Stores the value of the property to extend a component with.
    public int index = 0;

    public ComponentExtender()
    {
    } //ComponentExtender

    public boolean CanExtend(Object extendee)
    {
        // Extends any type of object.
        return true;
    } //CanExtend

    public int GetExtenderIndex(IComponent component)
    {
        return index;
    } //GetExtenderIndex

    public void SetExtenderIndex(IComponent component, int index)
    {
        this.index = index;
    } //SetExtenderIndex
} //ComponentExtender

// Example UserControl associated with the ExtenderServiceDesigner.
/** @ attribute DesignerAttribute(ExtenderServiceDesigner.class.ToType())
 */
public class ExtenderServiceTestControl extends 
    System.Windows.Forms.UserControl
{
    public ExtenderServiceTestControl()
    {
    } //ExtenderServiceTestControl
} //ExtenderServiceTestControl

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0
Afficher: