LocalizationExtenderProvider Clase

Definición

Precaución

This class has been deprecated. Use CodeDomLocalizationProvider instead. http://go.microsoft.com/fwlink/?linkid=14202

Proporciona a un diseñador raíz compatibilidad en tiempo de diseño para las características de localización.

public ref class LocalizationExtenderProvider : IDisposable, System::ComponentModel::IExtenderProvider
public class LocalizationExtenderProvider : IDisposable, System.ComponentModel.IExtenderProvider
[System.Obsolete("This class has been deprecated. Use CodeDomLocalizationProvider instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public class LocalizationExtenderProvider : IDisposable, System.ComponentModel.IExtenderProvider
type LocalizationExtenderProvider = class
    interface IExtenderProvider
    interface IDisposable
[<System.Obsolete("This class has been deprecated. Use CodeDomLocalizationProvider instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
type LocalizationExtenderProvider = class
    interface IExtenderProvider
    interface IDisposable
Public Class LocalizationExtenderProvider
Implements IDisposable, IExtenderProvider
Herencia
LocalizationExtenderProvider
Atributos
Implementaciones

Ejemplos

En el ejemplo de código siguiente se agrega un LocalizationExtenderProvider objeto a un componente.

// Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
extender = gcnew LocalizationExtenderProvider( this->component->Site,this->component );
// Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
extender = new LocalizationExtenderProvider(this.component.Site, this.component);
' Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
extender = New LocalizationExtenderProvider(Me.component_.Site, Me.component_)

En el ejemplo de código siguiente se incluye un componente de ejemplo y un diseñador. El diseñador usa un LocalizationExtenderProvider para agregar propiedades de compatibilidad de localización para el componente.

#using <system.dll>
#using <system.design.dll>
#using <system.windows.forms.dll>
#using <system.drawing.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Diagnostics;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

// This example demonstrates adding localization support to a component hierarchy from a
// custom IRootDesigner using the LocalizationExtenderProvider class.
namespace LocalizationExtenderProviderExample
{

   // Example IRootDesigner implementation demonstrates LocalizationExtenderProvider support.
   private ref class SampleRootDesigner: public IRootDesigner
   {
   private:

      // RootDesignerView is a simple control that will be displayed in the designer window.
      ref class RootDesignerView: public Control
      {
      private:
         SampleRootDesigner^ m_designer;
         IComponent^ comp;

      public:
         RootDesignerView( SampleRootDesigner^ designer, IComponent^ component )
         {
            m_designer = designer;
            this->comp = component;
            BackColor = Color::Blue;
            Font = gcnew System::Drawing::Font( FontFamily::GenericMonospace,12 );
         }


      protected:

         // Displays the name of the component and the name of the assembly of the component
         // that this root designer is providing support for.
         virtual void OnPaint( PaintEventArgs^ pe ) override
         {
            Control::OnPaint( pe );
            if ( m_designer != 0 && comp != 0 )
            {
               
               // Draws the name of the component in large letters.
               pe->Graphics->DrawString( "Root Designer View", Font, Brushes::Yellow, 8, 4 );
               pe->Graphics->DrawString( String::Concat( "Design Name  : ", comp->Site->Name ), gcnew System::Drawing::Font( "Arial",10 ), Brushes::Yellow, 8, 28 );
               pe->Graphics->DrawString( String::Concat( "Assembly    : ", comp->GetType()->AssemblyQualifiedName ), gcnew System::Drawing::Font( "Arial",10 ), Brushes::Yellow, System::Drawing::RectangleF( System::Drawing::Point( 8, 44 ), System::Drawing::Size( ClientRectangle.Width - 8, ClientRectangle.Height - 44 ) ) );
               
               // Uses the site of the component to acquire an ISelectionService and sets the property grid focus to the component.
               ISelectionService^ selectionService = dynamic_cast<ISelectionService^>(comp->Site->GetService( typeid<ISelectionService^> ));
               if ( selectionService != nullptr )
               {
                  array<IComponent^>^myArray = {m_designer->component};
                  selectionService->SetSelectedComponents( static_cast<Array^>(myArray) );
               }
            }
         }

      };


   protected:

      // RootDesignerView Control provides a full region designer view for this root designer's associated component.
      RootDesignerView^ m_view;

      // Stores reference to the LocalizationExtenderProvider this designer adds, in order to remove it on Dispose.
      LocalizationExtenderProvider^ extender;

      // Internally stores the IDesigner's component reference
      IComponent^ component;

      // Provides a RootDesignerView object that supports ViewTechnology.WindowsForms.
      Object^ GetView( ViewTechnology technology )
      {
         if ( technology != ViewTechnology::WindowsForms )
         {
            throw gcnew ArgumentException( "Not a supported view technology", "technology" );
         }

         if ( m_view == nullptr )
         {
            
            // Create the view control. In this example, a Control of type RootDesignerView is used.
            // A WindowsForms ViewTechnology view provider requires a class that inherits from Control.
            m_view = gcnew RootDesignerView( this,this->Component );
         }

         return m_view;
      }


      property array<ViewTechnology>^ SupportedTechnologies 
      {

         // This designer supports the WindowsForms view technology.
         array<ViewTechnology>^ IRootDesigner::get()
         {
            ViewTechnology myArray[] = {ViewTechnology::WindowsForms};
            return myArray;
         }

      }

   public:

      // Adds a LocalizationExtenderProvider for the component this designer is initialized to support.
      void Initialize( IComponent^ component )
      {
         this->component = component;
         
         // If no extender from this designer is active...
         if ( extender == nullptr )
         {
            
            // Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
            extender = gcnew LocalizationExtenderProvider( this->component->Site,this->component );
            
         }
      }


      property DesignerVerbCollection^ Verbs 
      {

         // Empty IDesigner interface property and method implementations
         DesignerVerbCollection^ get()
         {
            return nullptr;
         }

      }

      property IComponent^ Component 
      {
         IComponent^ get()
         {
            return this->component;
         }

      }
      void DoDefaultAction(){}

      void Dispose(){}


   protected:

      // If a LocalizationExtenderProvider has been added, removes the extender provider.
      void Dispose( bool disposing )
      {
         
         // If an extender has been added, remove it
         if ( extender != nullptr )
         {
            
            // Disposes of the extender provider.  The extender
            // provider removes itself from the extender provider
            // service when it is disposed.
            extender->Dispose();
            extender = nullptr;
         }
      }

   };


   // The following attribute associates the RootDesignedComponent with the RootDesignedComponent component.

   [Designer(__typeof(SampleRootDesigner),__typeof(IRootDesigner))]
   public ref class RootDesignedComponent: public Component
   {
   public:
      RootDesignedComponent(){}

   };


   // RootViewDesignerComponent is a component associated with the SampleRootDesigner
   // IRootDesigner that provides LocalizationExtenderProvider localization support.
   // This derived class is included at the top of this example to enable
   // easy launching of designer view without having to put the class in its own file.
   public ref class RootViewDesignerComponent: public RootDesignedComponent
   {
   public:
      RootViewDesignerComponent(){}

   };

}
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;

// This example demonstrates adding localization support to a component hierarchy from a 
// custom IRootDesigner using the LocalizationExtenderProvider class.
namespace LocalizationExtenderProviderExample
{	
    // RootViewDesignerComponent is a component associated with the SampleRootDesigner
    // IRootDesigner that provides LocalizationExtenderProvider localization support.
    // This derived class is included at the top of this example to enable 
    // easy launching of designer view without having to put the class in its own file.
    public class RootViewDesignerComponent : RootDesignedComponent
    {  
        public RootViewDesignerComponent()
        {            
        }
    }

    // The following attribute associates the RootDesignedComponent with the RootDesignedComponent component.
    [Designer(typeof(SampleRootDesigner), typeof(IRootDesigner))]
    public class RootDesignedComponent : Component
    {
        public RootDesignedComponent()
        {
        }    
    }

    // Example IRootDesigner implementation demonstrates LocalizationExtenderProvider support.
    internal class SampleRootDesigner : IRootDesigner
    {
        // RootDesignerView Control provides a full region designer view for this root designer's associated component.
        private RootDesignerView m_view;			
        // Stores reference to the LocalizationExtenderProvider this designer adds, in order to remove it on Dispose.
        private LocalizationExtenderProvider extender;        
        // Internally stores the IDesigner's component reference
        private IComponent component;                
        
        // Adds a LocalizationExtenderProvider for the component this designer is initialized to support.
        public void Initialize(System.ComponentModel.IComponent component)
        {
           this.component = component;
            
            // If no extender from this designer is active...
            if( extender == null )
            {
                // Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
                extender = new LocalizationExtenderProvider(this.component.Site, this.component);
            }
        }

        // Provides a RootDesignerView object that supports ViewTechnology.WindowsForms.
        object IRootDesigner.GetView(ViewTechnology technology) 
        {
            if (technology != ViewTechnology.WindowsForms)
            {
                throw new ArgumentException("Not a supported view technology", "technology");
            }
            if (m_view == null )
            {
                // Create the view control. In this example, a Control of type RootDesignerView is used.
                // A WindowsForms ViewTechnology view provider requires a class that inherits from Control.
                m_view = new RootDesignerView(this, this.Component);
            }
            return m_view;
        }

        // This designer supports the WindowsForms view technology.
        ViewTechnology[] IRootDesigner.SupportedTechnologies 
        {
            get
            {
                return new ViewTechnology[] {ViewTechnology.WindowsForms};
            }
        }
        
        // If a LocalizationExtenderProvider has been added, removes the extender provider.
        protected void Dispose(bool disposing)
        {            
            // If an extender has been added, remove it
            if( extender != null  )  
            {
                // Disposes of the extender provider.  The extender 
                // provider removes itself from the extender provider
                // service when it is disposed.
                extender.Dispose();
                extender = null;                
            }            
        }

        // Empty IDesigner interface property and method implementations
        public System.ComponentModel.Design.DesignerVerbCollection Verbs
        {
            get
            {
                return null;
            }
        }

        public System.ComponentModel.IComponent Component
        {
            get
            {
                return this.component;
            }
        }

        public void DoDefaultAction()
        {            
        }

        public void Dispose()
        {        
        }
        
        // RootDesignerView is a simple control that will be displayed in the designer window.
        private class RootDesignerView : Control
        {
            private SampleRootDesigner m_designer;   
            private IComponent comp;
            
            public RootDesignerView(SampleRootDesigner designer, IComponent component)
            {
                m_designer = designer;                        
                this.comp = component;      
                BackColor = Color.Blue;
                Font = new Font(FontFamily.GenericMonospace, 12);
            }

            // Displays the name of the component and the name of the assembly of the component 
            // that this root designer is providing support for.
            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);

                if( m_designer != null && comp != null )
                {
                    // Draws the name of the component in large letters.
                    pe.Graphics.DrawString("Root Designer View", Font, Brushes.Yellow, 8, 4);                    
                    pe.Graphics.DrawString("Design Name  : "+comp.Site.Name, new Font("Arial", 10), Brushes.Yellow, 8, 28);                    
                    pe.Graphics.DrawString("Assembly    : "+comp.GetType().AssemblyQualifiedName, new Font("Arial", 10), Brushes.Yellow, new Rectangle(new Point(8, 44), new Size(ClientRectangle.Width-8, ClientRectangle.Height-44)));                   

                    // Uses the site of the component to acquire an ISelectionService and sets the property grid focus to the component.
                    ISelectionService selectionService = (ISelectionService)comp.Site.GetService(typeof(ISelectionService));
                    if( selectionService != null )                
                        selectionService.SetSelectedComponents( new IComponent[] { m_designer.component } );             
                }
            }
        }
    }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Diagnostics
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Windows.Forms.Design

' This example demonstrates adding localization support to a component hierarchy from a 
' custom IRootDesigner using the LocalizationExtenderProvider class.

' RootViewDesignerComponent is a component associated with the SampleRootDesigner
' IRootDesigner that provides LocalizationExtenderProvider localization support.
' This derived class is included at the top of this example to enable 
' easy launching of designer view without having to put the class in its own file.
Public Class RootViewDesignerComponent
    Inherits RootDesignedComponent

    Public Sub New()
    End Sub
End Class

' The following attribute associates the RootDesignedComponent with the RootDesignedComponent component.
<Designer(GetType(SampleRootDesigner), GetType(IRootDesigner))> _
Public Class RootDesignedComponent
    Inherits Component

    Public Sub New()
    End Sub
End Class

' Example IRootDesigner implementation demonstrates LocalizationExtenderProvider support.
Friend Class SampleRootDesigner
    Implements IRootDesigner

    ' RootDesignerView Control provides a full region designer view for this root designer's associated component.
    Private m_view As RootDesignerView
    ' Stores reference to the LocalizationExtenderProvider this designer adds, in order to remove it on Dispose.
    Private extender As LocalizationExtenderProvider
    ' Internally stores the IDesigner's component reference
    Private component_ As IComponent

    ' Adds a LocalizationExtenderProvider for the component this designer is initialized to support.
    Public Sub Initialize(ByVal component As System.ComponentModel.IComponent) Implements IRootDesigner.Initialize
        Me.component_ = component

        ' If no extender from this designer is active...
        If extender Is Nothing Then
            ' Adds a LocalizationExtenderProvider that provides localization support properties to the specified component.
            extender = New LocalizationExtenderProvider(Me.component_.Site, Me.component_)
        End If
    End Sub

    ' Provides a RootDesignerView object that supports ViewTechnology.WindowsForms.
    Function GetView(ByVal technology As ViewTechnology) As Object Implements IRootDesigner.GetView

        If technology <> ViewTechnology.WindowsForms Then
            Throw New ArgumentException("Not a supported view technology", "technology")
        End If
        If m_view Is Nothing Then
            ' Create the view control. In this example, a Control of type RootDesignerView is used.
            ' A WindowsForms ViewTechnology view provider requires a class that inherits from Control.
            m_view = New RootDesignerView(Me, Me.Component)
        End If
        Return m_view

    End Function

    ' This designer supports the WindowsForms view technology.
    ReadOnly Property SupportedTechnologies() As ViewTechnology() Implements IRootDesigner.SupportedTechnologies
        Get
            Return New ViewTechnology() {ViewTechnology.WindowsForms}
        End Get
    End Property

    ' If a LocalizationExtenderProvider has been added, removes the extender provider.
    Protected Overloads Sub Dispose(ByVal disposing As Boolean)
        ' If an extender has been added, remove it
        If (extender IsNot Nothing) Then
            ' Disposes of the extender provider.  The extender 
            ' provider removes itself from the extender provider
            ' service when it is disposed.
            extender.Dispose()
            extender = Nothing
        End If
    End Sub

    ' Empty IDesigner interface property and method implementations
    Public ReadOnly Property Verbs() As System.ComponentModel.Design.DesignerVerbCollection Implements IDesigner.Verbs
        Get
            Return Nothing
        End Get
    End Property

    Public ReadOnly Property Component() As System.ComponentModel.IComponent Implements IRootDesigner.Component
        Get
            Return Me.component_
        End Get
    End Property

    Public Sub DoDefaultAction() Implements IDesigner.DoDefaultAction
    End Sub

    Public Overloads Sub Dispose() Implements IDisposable.Dispose
    End Sub

    ' RootDesignerView is a simple control that will be displayed in the designer window.
    Private Class RootDesignerView
        Inherits Control
        Private m_designer As SampleRootDesigner
        Private comp As IComponent

        Public Sub New(ByVal designer As SampleRootDesigner, ByVal component As IComponent)
            m_designer = designer
            Me.comp = component
            BackColor = Color.Blue
            Font = New Font(FontFamily.GenericMonospace, 12)
        End Sub

        ' Displays the name of the component and the name of the assembly of the component 
        ' that this root designer is providing support for.
        Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
            MyBase.OnPaint(pe)

            If (m_designer IsNot Nothing) AndAlso (comp IsNot Nothing) Then
                ' Draws the name of the component in large letters.
                pe.Graphics.DrawString("Root Designer View", Font, Brushes.Yellow, 8, 4)
                pe.Graphics.DrawString("Design Name  : " + comp.Site.Name, New Font("Arial", 10), Brushes.Yellow, 8, 28)
                
                ' Uses the site of the component to acquire an ISelectionService and sets the property grid focus to the component.
                Dim selectionService As ISelectionService = CType(comp.Site.GetService(GetType(ISelectionService)), ISelectionService)
                If (selectionService IsNot Nothing) Then
                    selectionService.SetSelectedComponents(New IComponent() {m_designer.Component})
                End If
            End If
        End Sub
    End Class

End Class

Comentarios

LocalizationExtenderProvider puede extender con IRootDesigner un conjunto de propiedades y métodos que proporcionan compatibilidad con la arquitectura de localización de .NET Framework. Para obtener más información sobre el uso de recursos, consulte Localización.

La arquitectura de compatibilidad de localización permite a los diseñadores inicializar propiedades de componente mediante archivos de recursos que se pueden intercambiar en tiempo de ejecución para admitir diversos lenguajes, estilos específicos de la referencia cultural y características configurables dinámicamente. Puede usar los métodos de esta clase para permitir que los diseñadores y el código que generan serializadores se carguen a partir de recursos y compilen código de inicialización que use características de localización.

Los serializadores predeterminados que se incluyen con Visual Studio ya son capaces de localizar componentes y controles, pero solo lo hacen si localizan la compatibilidad con la arquitectura de localización de .NET Framework. Para detectar la presencia de compatibilidad con la localización, el sistema de serialización debe localizar una propiedad pública Boolean denominada "Localizable" en el componente del diseñador raíz. Si un serializador encuentra esta propiedad, busca una propiedad de tipo CultureInfo denominada "Language" para determinar la configuración de recursos actual. Los serializadores predeterminados usan estas propiedades para determinar si debe localizar los recursos localizables del componente y, si es así, en qué CultureInfo formato se debe guardar la información del recurso.

Constructores

LocalizationExtenderProvider(ISite, IComponent)
Obsoletos.

Inicializa una nueva instancia de la clase LocalizationExtenderProvider mediante el proveedor de servicios principal especificado y el componente base.

Métodos

CanExtend(Object)
Obsoletos.

Indica si este objeto puede proporcionar las propiedades extensoras al objeto especificado.

Dispose()
Obsoletos.

Se deshace de los recursos (distintos de la memoria) que usa LocalizationExtenderProvider.

Dispose(Boolean)
Obsoletos.

Libera los recursos no administrados que usa LocalizationExtenderProvider y, de forma opcional, libera los recursos administrados.

Equals(Object)
Obsoletos.

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()
Obsoletos.

Sirve como la función hash predeterminada.

(Heredado de Object)
GetLanguage(Object)
Obsoletos.

Obtiene la referencia cultural de recursos actual para el objeto especificado.

GetLoadLanguage(Object)
Obsoletos.

Obtiene la referencia cultural de recursos predeterminada al inicializar los valores de un objeto localizado en tiempo de diseño.

GetLocalizable(Object)
Obsoletos.

Obtiene un valor que indica si el objeto especificado admite la localización de recursos.

GetType()
Obsoletos.

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()
Obsoletos.

Crea una copia superficial del Object actual.

(Heredado de Object)
ResetLanguage(Object)
Obsoletos.

Restablece la referencia cultural de recursos para el objeto especificado.

SetLanguage(Object, CultureInfo)
Obsoletos.

Establece que la referencia cultural de recursos actual para el objeto especificado sea la referencia cultural de recursos especificada.

SetLocalizable(Object, Boolean)
Obsoletos.

Establece un valor que indica si el objeto especificado admite recursos localizados.

ShouldSerializeLanguage(Object)
Obsoletos.

Obtiene un valor que indica si los valores localizables del objeto especificado se deben conservar en un recurso.

ToString()
Obsoletos.

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a