ערוך

שתף באמצעות


IPropertyValueUIService Interface

Definition

Provides an interface to manage the images, ToolTips, and event handlers for the properties of a component displayed in a property browser.

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

Examples

The following code example creates a component that obtains an instance of the IPropertyValueUIService interface and adds a PropertyValueUIHandler to the service. The handler provides a PropertyValueUIItem object for any properties of the component named HorizontalMargin or VerticalMargin. The PropertyValueUIItem for these properties provides an image, a ToolTip, and an event handler that displays a message box when the image for the property is clicked. The image and the ToolTip are displayed in a PropertyGrid when the grid is showing these properties of the component.

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

Remarks

A component can use the IPropertyValueUIService interface to provide PropertyValueUIItem objects for any properties of the component. A PropertyValueUIItem associated with a property can provide an image, a ToolTip and an event handler for the event that is raised when the image associated with the property is clicked.

The IPropertyValueUIService interface provides methods to add, remove, and retrieve PropertyValueUIHandler delegates to or from an internal list. When the properties of a component are displayed in a property browser, each PropertyValueUIHandler in the list is given an opportunity to provide a PropertyValueUIItem for each property of the component.

When a property browser is set to display the properties of an object, it calls the GetPropertyUIValueItems method of this interface for each property of the component, passing a PropertyDescriptor that represents the property. The GetPropertyUIValueItems method calls each PropertyValueUIHandler that has been added to the service. Each PropertyValueUIHandler can add a PropertyValueUIItem to the ArrayList parameter passed in the valueUIItemList parameter to supply UI items for the property represented by the PropertyDescriptor passed in the propDesc parameter.

A PropertyValueUIItem can contain an image to display next to the property name, a ToolTip string, and an event handler to invoke when an image associated with the property is double-clicked.

Methods

AddPropertyValueUIHandler(PropertyValueUIHandler)

Adds the specified PropertyValueUIHandler to this service.

GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor)

Gets the PropertyValueUIItem objects that match the specified context and property descriptor characteristics.

NotifyPropertyValueUIItemsChanged()

Notifies the IPropertyValueUIService implementation that the global list of PropertyValueUIItem objects has been modified.

RemovePropertyValueUIHandler(PropertyValueUIHandler)

Removes the specified PropertyValueUIHandler from the property value UI service.

Events

PropertyUIValueItemsChanged

Occurs when the list of PropertyValueUIItem objects is modified.

Applies to

See also