IPropertyValueUIService Interfejs

Definicja

Udostępnia interfejs do zarządzania obrazami, etykietkami narzędzi i procedurami obsługi zdarzeń dla właściwości składnika wyświetlanego w przeglądarce właściwości.

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

Przykłady

Poniższy przykład kodu tworzy składnik, który uzyskuje wystąpienie interfejsu IPropertyValueUIService i dodaje element PropertyValueUIHandler do usługi. Procedura obsługi udostępnia PropertyValueUIItem obiekt dla wszystkich właściwości składnika o nazwie HorizontalMargin lub VerticalMargin. Dla PropertyValueUIItem tych właściwości udostępnia obraz, etykietkę narzędzia i procedurę obsługi zdarzeń, która wyświetla okno komunikatu po kliknięciu obrazu dla właściwości. Obraz i etykietka narzędzia są wyświetlane w elemencie PropertyGrid , gdy siatka wyświetla te właściwości składnika.

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

Uwagi

Składnik może używać interfejsu IPropertyValueUIService do udostępniania PropertyValueUIItem obiektów dla dowolnych właściwości składnika. Obiekt PropertyValueUIItem skojarzony z właściwością może dostarczyć obraz, etykietkę narzędzia i procedurę obsługi zdarzeń dla zdarzenia, które jest zgłaszane po kliknięciu obrazu skojarzonego z właściwością.

Interfejs udostępnia metody dodawania IPropertyValueUIService , usuwania i pobierania PropertyValueUIHandler delegatów do lub z listy wewnętrznej. Gdy właściwości składnika są wyświetlane w przeglądarce właściwości, każda PropertyValueUIHandler z nich ma możliwość udostępnienia PropertyValueUIItem każdej właściwości składnika.

Gdy przeglądarka właściwości jest ustawiona na wyświetlanie właściwości obiektu, wywołuje GetPropertyUIValueItems metodę tego interfejsu dla każdej właściwości składnika, przekazując element PropertyDescriptor reprezentujący właściwość . Metoda GetPropertyUIValueItems wywołuje każdy PropertyValueUIHandler element, który został dodany do usługi. Każdy PropertyValueUIHandler element może dodać PropertyValueUIItem element do parametru przekazanego ArrayList w parametrze valueUIItemList w celu podania elementów interfejsu użytkownika dla właściwości reprezentowanej przez PropertyDescriptor przekazany w parametrze propDesc .

Obiekt PropertyValueUIItem może zawierać obraz do wyświetlenia obok nazwy właściwości, ciągu ToolTip i procedury obsługi zdarzeń do wywołania, gdy obraz skojarzony z właściwością jest dwukrotnie kliknięty.

Metody

AddPropertyValueUIHandler(PropertyValueUIHandler)

Dodaje określony PropertyValueUIHandler element do tej usługi.

GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor)

PropertyValueUIItem Pobiera obiekty zgodne z określonym kontekstem i właściwościami deskryptora.

NotifyPropertyValueUIItemsChanged()

Powiadamia implementację IPropertyValueUIService o modyfikacji globalnej PropertyValueUIItem listy obiektów.

RemovePropertyValueUIHandler(PropertyValueUIHandler)

Usuwa określony PropertyValueUIHandler element z usługi interfejsu użytkownika wartości właściwości.

Zdarzenia

PropertyUIValueItemsChanged

Występuje, gdy lista PropertyValueUIItem obiektów jest modyfikowana.

Dotyczy

Zobacz też