Export (0) Print
Expand All

IExtenderProviderService Interface

Provides an interface for adding and removing extender providers at design time.

For a list of all members of this type, see IExtenderProviderService Members.

[Visual Basic]
Public Interface IExtenderProviderService
[C#]
public interface IExtenderProviderService
[C++]
public __gc __interface IExtenderProviderService
[JScript]
public interface IExtenderProviderService

Remarks

Typically, only components that have been added to a container offer extender providers. The IExtenderProviderService allows you to extend this capability to objects that are not in the container.

Example

[Visual Basic, C#, C++] The following example demosntrates using the IExtenderProviderService from a designer to add and remove an IExtenderProvider implementation.

[Visual Basic] 
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

' This designer adds a ComponentExtender extender provider, 
' and removes it when the designer is destroyed.
Public Class ExtenderServiceDesigner
    Inherits System.Windows.Forms.Design.ControlDesigner

   ' A local reference to an obtained IExtenderProviderService.
   Private localExtenderServiceReference As IExtenderProviderService
   ' An IExtenderProvider that this designer supplies.
   Private extender As ComponentExtender   
   
   Public Sub New()
    End Sub

    Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
        MyBase.Initialize(component)

        ' Attempts to obtain an IExtenderProviderService.
        Dim extenderService As IExtenderProviderService = CType(component.Site.GetService(GetType(IExtenderProviderService)), IExtenderProviderService)
        If Not (extenderService Is Nothing) Then
            ' 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.")
        End If
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        ' Removes any previously added extender provider.
        If Not (localExtenderServiceReference Is Nothing) Then
            localExtenderServiceReference.RemoveExtenderProvider(extender)
            localExtenderServiceReference = Nothing
        End If
    End Sub
End Class

' IExtenderProviderImplementation that adds an integer property 
' named "ExtenderIndex" to any design-mode document object.
<ProvidePropertyAttribute("ExtenderIndex", GetType(IComponent))> _
Public Class ComponentExtender
    Implements System.ComponentModel.IExtenderProvider

    ' Stores the value of the property to extend a component with.
    Public index As Integer = 0

    Public Sub New()
    End Sub

    ' Extends any type of object.
    Public Function CanExtend(ByVal extendee As Object) As Boolean Implements IExtenderProvider.CanExtend
        Return True
    End Function

    Public Function GetExtenderIndex(ByVal component As IComponent) As Integer
        Return index
    End Function

    Public Sub SetExtenderIndex(ByVal component As IComponent, ByVal index As Integer)
        Me.index = index
    End Sub
End Class

' Example UserControl associated with the ExtenderServiceDesigner.
<DesignerAttribute(GetType(ExtenderServiceDesigner))> _
Public Class ExtenderServiceTestControl
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
    End Sub
End Class

[C#] 
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()
        {                        
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>
#using <system.design.dll>
#using <system.windows.forms.dll>
#using <system.drawing.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

namespace ExtenderServiceExample
{
    // IExtenderProviderImplementation that adds an integer property
    // named "ExtenderIndex" to any design-mode document object.
    [ProvidePropertyAttribute(S"ExtenderIndex", __typeof(IComponent))]
    public __gc class ComponentExtender : public IExtenderProvider {
    public:

        // Stores the value of the property to extend a component with.
        int index;

        ComponentExtender()
        {
            index = 0;
        }

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

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

        void SetExtenderIndex(IComponent* component, int index)
        {
            this->index = index;
        }
    };

    // This designer adds a ComponentExtender extender provider,
    // and removes it when the designer is destroyed.
    public __gc class ExtenderServiceDesigner : public ControlDesigner {
    private:

        // A local reference to an obtained IExtenderProviderService.
        IExtenderProviderService* localExtenderServiceReference;
        // An IExtenderProvider that this designer supplies.
        ComponentExtender* extender;

    public:

        ExtenderServiceDesigner()
        {
        }

        void Initialize(IComponent* component)
        {
            ControlDesigner::Initialize(component);

            // Attempts to obtain an IExtenderProviderService.
            IExtenderProviderService* extenderService = dynamic_cast<IExtenderProviderService*>(component->Site->GetService(__typeof(IExtenderProviderService)));
            if( extenderService != 0 )
            {
                // 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(S"Could not obtain an IExtenderProviderService.");
        }

    protected:

        void Dispose(bool disposing)
        {
            // Removes any previously added extender provider.
            if( localExtenderServiceReference != 0 )
            {
                localExtenderServiceReference->RemoveExtenderProvider( extender );
                localExtenderServiceReference = 0;
            }
        }
    };

    // Example UserControl associated with the ExtenderServiceDesigner.
    [DesignerAttribute(__typeof(ExtenderServiceDesigner))]
    public __gc class ExtenderServiceTestControl : public UserControl {
    public:

        ExtenderServiceTestControl()
        {
        }
    };
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel.Design

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

IExtenderProviderService Members | System.ComponentModel.Design Namespace | IExtenderProvider

Show:
© 2015 Microsoft