Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

LocalizationExtenderProvider Class

NOTE: This class is now obsolete. The non-obsolete alternative is CodeDomLocalizationProvider.

Provides design-time support for localization features to a root designer.

Namespace: System.ComponentModel.Design
Assembly: System.Design (in system.design.dll)

[ObsoleteAttribute("This class has been deprecated. Use CodeDomLocalizationProvider instead.  http://go.microsoft.com/fwlink/?linkid=14202")] 
public class LocalizationExtenderProvider : IExtenderProvider, IDisposable
/** @attribute ObsoleteAttribute("This class has been deprecated. Use CodeDomLocalizationProvider instead.  http://go.microsoft.com/fwlink/?linkid=14202") */ 
public class LocalizationExtenderProvider implements IExtenderProvider, IDisposable
ObsoleteAttribute("This class has been deprecated. Use CodeDomLocalizationProvider instead.  http://go.microsoft.com/fwlink/?linkid=14202") 
public class LocalizationExtenderProvider implements IExtenderProvider, IDisposable
Not applicable.

LocalizationExtenderProvider can extend an IRootDesigner with a set of properties and methods that provide support for the .NET Framework localization architecture. For more about using resources, see Localization.

The localization support architecture enables designers to initialize component properties using resource files that can be swapped at run time to support a variety of languages, culture-specific styles and dynamically configurable features. You can use the methods of this class to enable designers and code generating serializers to load from resources and build initialization code that uses localization features.

The default serializers that ship with Visual Studio are already capable of localizing components and controls, but they only do so if they locate support for the .NET Framework localization architecture. To detect the presence of localization support, the serialization system must locate a public Boolean property named “Localizable” on the root designer component. If a serializer finds this property, it searches for a property of type CultureInfo named "Language" to determine the current resource configuration. Default serializers use these properties to determine if it should localize any localizable resources of the component, and if so, what CultureInfo format the resource information should be saved in.

The following code example adds a LocalizationExtenderProvider to a 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(
    this.component.get_Site(), this.component);

The following code example includes an example component and designer. The designer uses a LocalizationExtenderProvider to add localization support properties for the component.

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 } );             
                }
            }
        }
    }
}

package LocalizationExtenderProviderExample;

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Diagnostics.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import 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 extends RootDesignedComponent
{
    public RootViewDesignerComponent()
    {
    } //RootViewDesignerComponent
} //RootViewDesignerComponent

// The following attribute associates the RootDesignedComponent with the 
// RootDesignedComponent component.
/** @attribute Designer(SampleRootDesigner.class, IRootDesigner.class)
 */
public class RootDesignedComponent extends Component
{
    public RootDesignedComponent()
    {
    } //RootDesignedComponent
} //RootDesignedComponent

// Example IRootDesigner implementation demonstrates 
// LocalizationExtenderProvider support.
class SampleRootDesigner implements IRootDesigner
{
    // RootDesignerView Control provides a full region designer view for 
    // this root designer's associated component.
    private RootDesignerView mView;

    // 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.get_Site(), this.component);
        }
    } //Initialize
    
    // Provides a RootDesignerView object that supports 
    // ViewTechnology.WindowsForms.
    public Object GetView(ViewTechnology technology)
    {
        if (!technology.Equals(ViewTechnology.WindowsForms)) {
            throw new ArgumentException("Not a supported view technology",
                "technology");
        }
        if (mView == 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.
            mView = new RootDesignerView(this, this.component);
        }
        return mView;
    } //IRootDesigner.GetView

    // This designer supports the WindowsForms view technology.
    /** @property 
     */
    public ViewTechnology[] get_SupportedTechnologies()
    {
        return new ViewTechnology[] { ViewTechnology.WindowsForms };
    } // get_SupportedTechnologies

    // If a LocalizationExtenderProvider has been added, 
    // removes the extender provider.
    protected void Dispose(boolean 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;
        }
    } //Dispose

    // Empty IDesigner interface property and method implementations
    /** @property 
     */
    public System.ComponentModel.Design.DesignerVerbCollection get_Verbs()
    {
        return null;
    } //get_Verbs

    /** @property 
     */
    public System.ComponentModel.IComponent get_Component()
    {
        return this.component;
    } //get_Component

    public void DoDefaultAction()
    {
    } //DoDefaultAction

    public void Dispose()
    {
    } //Dispose

    // RootDesignerView is a simple control that will be displayed 
    // in the designer window.
    private class RootDesignerView extends Control
    {
        private SampleRootDesigner mDesigner;
        private IComponent comp;

        public RootDesignerView(SampleRootDesigner designer, 
            IComponent component)
        {
            mDesigner = designer;
            this.comp = component;
            set_BackColor(Color.get_Blue());
            set_Font(new Font(FontFamily.get_GenericMonospace(), 12));
        } //RootDesignerView

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

            if (mDesigner != null && comp != null) {
                // Draws the name of the component in large letters.
                pe.get_Graphics().DrawString("Root Designer View", get_Font(), 
                    Brushes.get_Yellow(), 8, 4);
                pe.get_Graphics().DrawString("Design Name  : " 
                    + comp.get_Site().get_Name(), new Font("Arial", 10), 
                    Brushes.get_Yellow(), 8, 28);
                pe.get_Graphics().DrawString("Assembly    : " 
                    + comp.GetType().get_AssemblyQualifiedName(), 
                    new Font("Arial", 10), Brushes.get_Yellow(), 
                    new RectangleF(new PointF(8, 44), 
                    new SizeF((float)(get_ClientRectangle().get_Width() - 8), 
                    (float)(get_ClientRectangle().get_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.
                    get_Site().GetService(ISelectionService.class.ToType()));
                if (selectionService != null) {
                    selectionService.SetSelectedComponents(new IComponent[] 
                        { mDesigner.component });
                }
            }
        } //OnPaint
    } //RootDesignerView
} //SampleRootDesigner

System.Object
  System.ComponentModel.Design.LocalizationExtenderProvider
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.