IPropertyValueUIService Interfaz

Definición

Proporciona una interfaz para administrar las imágenes, la información sobre herramientas y los controladores de eventos para las propiedades de un componente mostrado en un explorador de propiedades.

public interface class IPropertyValueUIService
public interface IPropertyValueUIService
type IPropertyValueUIService = interface
Public Interface IPropertyValueUIService

Ejemplos

En el ejemplo de código siguiente se crea un componente que obtiene una instancia de la IPropertyValueUIService interfaz y agrega un PropertyValueUIHandler elemento al servicio. El controlador proporciona un PropertyValueUIItem objeto para cualquier propiedad del componente denominado HorizontalMargin o VerticalMargin. Para PropertyValueUIItem estas propiedades proporciona una imagen, una información sobre herramientas y un controlador de eventos que muestra un cuadro de mensaje cuando se hace clic en la imagen de la propiedad. La imagen y la información sobre herramientas se muestran en un PropertyGrid cuando la cuadrícula muestra estas propiedades del componente.

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

namespace PropertyValueUIServiceExample
{
    // This component obtains the IPropertyValueUIService and adds a
    // PropertyValueUIHandler that provides PropertyValueUIItem objects,
    // which provide an image, ToolTip, and invoke event handler to
    // any properties named HorizontalMargin and VerticalMargin, 
    // such as the example integer properties on this component.    
    public class PropertyUIComponent : System.ComponentModel.Component
    {
        // Example property for which to provide a PropertyValueUIItem.
        public int HorizontalMargin { get; set; }

        // Example property for which to provide a PropertyValueUIItem.
        public int VerticalMargin { get; set; }

        // Field storing the value of the VerticalMargin property.
        private int vMargin;

        // Constructor.
        public PropertyUIComponent(System.ComponentModel.IContainer container)
        {
            if (container != null)
                container.Add(this);
            HorizontalMargin = 0;
            VerticalMargin = 0;
        }

        // Default component constructor that specifies no container.
        public PropertyUIComponent() : this(null)
        { }

        // PropertyValueUIHandler delegate that provides PropertyValueUIItem
        // objects to any properties named HorizontalMargin or VerticalMargin.
        private void marginPropertyValueUIHandler(
            System.ComponentModel.ITypeDescriptorContext context,
            System.ComponentModel.PropertyDescriptor propDesc,
            ArrayList itemList)
        {
            // A PropertyValueUIHandler added to the IPropertyValueUIService
            // is queried once for each property of a component and passed
            // a PropertyDescriptor that represents the characteristics of 
            // the property when the Properties window is set to a new 
            // component. A PropertyValueUIHandler can determine whether 
            // to add a PropertyValueUIItem for the object to its ValueUIItem 
            // list depending on the values of the PropertyDescriptor.
            if (propDesc.DisplayName.Equals("HorizontalMargin"))
            {
                Image img = Image.FromFile("SampImag.jpg");
                itemList.Add(new PropertyValueUIItem(img, new PropertyValueUIItemInvokeHandler(this.marginInvoke), "Test ToolTip"));
            }
            if (propDesc.DisplayName.Equals("VerticalMargin"))
            {
                Image img = Image.FromFile("SampImag.jpg");
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                itemList.Add(new PropertyValueUIItem(img, new PropertyValueUIItemInvokeHandler(this.marginInvoke), "Test ToolTip"));
            }
        }

        // Invoke handler associated with the PropertyValueUIItem objects 
        // provided by the marginPropertyValueUIHandler.
        private void marginInvoke(System.ComponentModel.ITypeDescriptorContext context, System.ComponentModel.PropertyDescriptor propDesc, PropertyValueUIItem item)
        {
            MessageBox.Show("Test invoke message box");
        }

        // Component.Site override to add the marginPropertyValueUIHandler
        // when the component is sited, and to remove it when the site is 
        // set to null.
        public override System.ComponentModel.ISite Site
        {
            get
            {
                return base.Site;
            }
            set
            {
                if (value != null)
                {
                    base.Site = value;
                    IPropertyValueUIService uiService = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));
                    if (uiService != null)
                        uiService.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
                }
                else
                {
                    IPropertyValueUIService uiService = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));
                    if (uiService != null)
                        uiService.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
                    base.Site = value;
                }
            }
        }
    }
}

Comentarios

Un componente puede usar la IPropertyValueUIService interfaz para proporcionar PropertyValueUIItem objetos para cualquier propiedad del componente. Un PropertyValueUIItem asociado a una propiedad puede proporcionar una imagen, una información sobre herramientas y un controlador de eventos para el evento que se genera cuando se hace clic en la imagen asociada a la propiedad .

La IPropertyValueUIService interfaz proporciona métodos para agregar, quitar y recuperar PropertyValueUIHandler delegados a o desde una lista interna. Cuando las propiedades de un componente se muestran en un explorador de propiedades, cada PropertyValueUIHandler una de las listas tiene la oportunidad de proporcionar una PropertyValueUIItem para cada propiedad del componente.

Cuando se establece un explorador de propiedades para mostrar las propiedades de un objeto, llama al GetPropertyUIValueItems método de esta interfaz para cada propiedad del componente, pasando un PropertyDescriptor que representa la propiedad . El GetPropertyUIValueItems método llama a cada uno de los PropertyValueUIHandler que se ha agregado al servicio. Cada PropertyValueUIHandler uno puede agregar un PropertyValueUIItem elemento al ArrayList parámetro pasado en el valueUIItemList parámetro para proporcionar elementos de interfaz de usuario para la propiedad representada por el PropertyDescriptor pasado en el propDesc parámetro .

Puede PropertyValueUIItem contener una imagen para mostrar junto al nombre de propiedad, una cadena de información sobre herramientas y un controlador de eventos que se invocarán cuando se haga doble clic en una imagen asociada a la propiedad.

Métodos

Nombre Description
AddPropertyValueUIHandler(PropertyValueUIHandler)

Agrega el especificado PropertyValueUIHandler a este servicio.

GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor)

Obtiene los PropertyValueUIItem objetos que coinciden con las características de contexto y descriptor de propiedad especificadas.

NotifyPropertyValueUIItemsChanged()

Notifica a la IPropertyValueUIService implementación que se ha modificado la lista global de PropertyValueUIItem objetos.

RemovePropertyValueUIHandler(PropertyValueUIHandler)

Quita el especificado PropertyValueUIHandler del servicio de interfaz de usuario de valor de propiedad.

Eventos

Nombre Description
PropertyUIValueItemsChanged

Se produce cuando se modifica la lista de PropertyValueUIItem objetos.

Se aplica a

Consulte también