IPropertyValueUIService Schnittstelle

Definition

Stellt eine Schnittstelle zum Verwalten der Bilder, QuickInfos und Ereignishandler für die Eigenschaften einer in einem Eigenschaftenbrowser angezeigten Komponente bereit.

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

Beispiele

Im folgenden Codebeispiel wird eine Komponente erstellt, die eine Instanz der IPropertyValueUIService -Schnittstelle abruft und dem Dienst eine PropertyValueUIHandler hinzufügt. Der Handler stellt ein PropertyValueUIItem -Objekt für alle Eigenschaften der Komponente mit dem Namen HorizontalMargin oder VerticalMarginbereit. Die PropertyValueUIItem für diese Eigenschaften stellt ein Bild, eine QuickInfo und einen Ereignishandler bereit, der ein Meldungsfeld anzeigt, wenn auf das Bild für die Eigenschaft geklickt wird. Das Bild und die QuickInfo werden in einem PropertyGrid angezeigt, wenn im Raster diese Eigenschaften der Komponente angezeigt werden.

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

Hinweise

Eine Komponente kann die IPropertyValueUIService -Schnittstelle verwenden, um Objekte für beliebige Eigenschaften der Komponente bereitzustellen PropertyValueUIItem . Eine PropertyValueUIItem einer -Eigenschaft zugeordnete kann ein Bild, eine QuickInfo und einen Ereignishandler für das Ereignis bereitstellen, das ausgelöst wird, wenn auf das der Eigenschaft zugeordnete Bild geklickt wird.

Die IPropertyValueUIService -Schnittstelle bietet Methoden zum Hinzufügen, Entfernen und Abrufen PropertyValueUIHandler von Delegaten zu oder aus einer internen Liste. Wenn die Eigenschaften einer Komponente in einem Eigenschaftenbrowser angezeigt werden, erhält jeder PropertyValueUIHandler in der Liste die Möglichkeit, für jede Eigenschaft der Komponente eine PropertyValueUIItem anzugeben.

Wenn ein Eigenschaftenbrowser so festgelegt ist, dass die Eigenschaften eines Objekts angezeigt werden, ruft er die GetPropertyUIValueItems -Methode dieser Schnittstelle für jede Eigenschaft der Komponente auf, wobei ein PropertyDescriptor übergeben wird, das die -Eigenschaft darstellt. Die GetPropertyUIValueItems -Methode ruft alle PropertyValueUIHandler Aufrufe auf, die dem Dienst hinzugefügt wurden. Jeder PropertyValueUIHandler kann dem Parameter, der ArrayList im valueUIItemList Parameter übergeben wird, eine PropertyValueUIItem hinzufügen, um UI-Elemente für die Eigenschaft anzugeben, die durch den PropertyDescriptor übergebenen Parameter dargestellt wirdpropDesc.

Ein PropertyValueUIItem kann ein Bild enthalten, das neben dem Eigenschaftennamen angezeigt werden soll, eine QuickInfo-Zeichenfolge und einen Ereignishandler, der aufgerufen werden soll, wenn auf ein der Eigenschaft zugeordnetes Bild doppelklicken wird.

Methoden

AddPropertyValueUIHandler(PropertyValueUIHandler)

Fügt diesem Dienst den angegebenen PropertyValueUIHandler hinzu.

GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor)

Ruft die PropertyValueUIItem-Objekte ab, die mit den angegebenen Merkmalen von Kontext und Eigenschaftenbezeichner übereinstimmen.

NotifyPropertyValueUIItemsChanged()

Benachrichtigt die IPropertyValueUIService-Implementierung von einer Änderung der globalen Liste von PropertyValueUIItem-Objekten.

RemovePropertyValueUIHandler(PropertyValueUIHandler)

Entfernt den angegebenen PropertyValueUIHandler aus dem Benutzeroberflächendienst für Eigenschaftswerte.

Ereignisse

PropertyUIValueItemsChanged

Tritt ein, wenn die Liste der PropertyValueUIItem-Objekte geändert wird.

Gilt für:

Weitere Informationen