Export (0) Print
Expand All

IPropertyValueUIService Interface

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

Namespace: System.Drawing.Design
Assembly: System.Drawing (in system.drawing.dll)

public interface IPropertyValueUIService
public interface IPropertyValueUIService
public interface IPropertyValueUIService
Not applicable.

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.

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;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
using System.Windows.Forms.Design;

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
            {
                return hMargin;
            }
            set
            {
                hMargin = value;
            }
        }
        // Example property for which to provide a PropertyValueUIItem.
        public int VerticalMargin
        {
            get
            {
                return vMargin;
            }
            set
            {
                vMargin = value;
            }
        }

        // Field storing the value of the HorizontalMargin property.
        private int hMargin;

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

        // Base64-encoded serialized image data for image icon.
        private string imageBlob1 = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYXABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIAAAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD///////////////////////////////////8AAAD///////////////8AAAD///////8AAAD///////////////8AAAD///////8AAAD///8AAAAAAAD///8AAAD///////8AAAD///8AAAAAAAD///8AAAD///////8AAAD///////////////8AAAD///////8AAAD///////////////8AAAD///////////////////////////////////8L";
                
        // Constructor.
        public PropertyUIComponent(System.ComponentModel.IContainer container)
        {
            if( container != null )
                container.Add(this);
            hMargin = 0;		
            vMargin = 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 = DeserializeFromBase64Text(imageBlob1);
                itemList.Add( new PropertyValueUIItem( img, new PropertyValueUIItemInvokeHandler(this.marginInvoke), "Test ToolTip") );
            }
            if( propDesc.DisplayName.Equals( "VerticalMargin" ) )
            {
                Image img = DeserializeFromBase64Text(imageBlob1);
                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;
                }
            }
        }

        // This method can be used to retrieve an Image from a block 
        // of Base64-encoded text.
        private Image DeserializeFromBase64Text(string text)
        {
            Image img = null;
            byte[] memBytes = Convert.FromBase64String(text);
            IFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream(memBytes);
            img = (Image)formatter.Deserialize(stream);
            stream.Close();
            return img;
        }
    }
}

package PropertyValueUIServiceExample; 

import System.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Drawing.Design.*;
import System.IO.*; 
import System.Runtime.Serialization.*;
import System.Runtime.Serialization.Formatters.Binary.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;
   
// 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 extends System.ComponentModel.Component
{
    // Example property for which to provide a PropertyValueUIItem.
    /** @property 
     */
    public int get_HorizontalMargin()
    {
        return hMargin;
    } //get_HorizontalMargin

    /** @property 
     */
    public void set_HorizontalMargin(int value)
    {
        hMargin = value;
    } //set_HorizontalMargin

    // Example property for which to provide a PropertyValueUIItem.
    /** @property 
     */
    public int get_VerticalMargin()
    {
        return vMargin;
    } //get_VerticalMargin

    /** @property 
     */
    public void set_VerticalMargin(int value)
    {
        vMargin = value;
    } //set_VerticalMargin

    // Field storing the value of the HorizontalMargin property.
    private int hMargin;

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

    // Base64-encoded serialized image data for image icon.
    private String imageBlob1 = "AAEAAAD/////AQAAAAAAAAAMAgAAAFRTeXN0ZW0uRHJh"
        +"d2luZywgVmVyc2lvbj0xLjAuMzMwMC4wLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0t"
        +"leVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJhd2luZy5CaXRtYX"
        +"ABAAAABERhdGEHAgIAAAAJAwAAAA8DAAAA9gAAAAJCTfYAAAAAAAAANgAAACgAAAAIA"
        +"AAACAAAAAEAGAAAAAAAAAAAAMQOAADEDgAAAAAAAAAAAAD/////////////////////"
        +"//////////////8AAAD///////////////8AAAD///////8AAAD///////////////8"
        +"AAAD///////8AAAD///8AAAAAAAD///8AAAD///////8AAAD///8AAAAAAAD///8AAA"
        +"D///////8AAAD///////////////8AAAD///////8AAAD///////////////8AAAD//"
        +"/////////////////////////////////8L";

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

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

    // 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.get_DisplayName().Equals("HorizontalMargin")) {
            Image img = DeserializeFromBase64Text(imageBlob1);

            itemList.Add(new PropertyValueUIItem(img, 
                new PropertyValueUIItemInvokeHandler(this.MarginInvoke),
                "Test ToolTip"));
        }
        if (propDesc.get_DisplayName().Equals("VerticalMargin")) {
            Image img = DeserializeFromBase64Text(imageBlob1);

            img.RotateFlip(RotateFlipType.Rotate90FlipNone);
            itemList.Add(new PropertyValueUIItem(img, 
                new PropertyValueUIItemInvokeHandler(this.MarginInvoke),
                "Test ToolTip"));
        }
    } //MarginPropertyValueUIHandler

    // 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");
    } //MarginInvoke

    // Component.Site override to add the MarginPropertyValueUIHandler
    // when the component is sited, and to remove it when the site is 
    // set to null.
    /** @property
     */
    public System.ComponentModel.ISite get_Site()
    {
        return super.get_Site();
    } //get_Site

    /** @property 
     */
    public void set_Site(System.ComponentModel.ISite value)
    {
        if (value != null) {
            super.set_Site(value);

            IPropertyValueUIService uiService 
                = ((IPropertyValueUIService)(this.
                GetService(IPropertyValueUIService.class.ToType())));
            if (uiService != null) {
                uiService.AddPropertyValueUIHandler(
                    new PropertyValueUIHandler(
                    this.MarginPropertyValueUIHandler));
            }
        }
        else {
            IPropertyValueUIService uiService = ((IPropertyValueUIService)(
                this.GetService(IPropertyValueUIService.class.ToType())));
            if (uiService != null) {
                uiService.RemovePropertyValueUIHandler(
                    new PropertyValueUIHandler(
                    this.MarginPropertyValueUIHandler));
            }
            super.set_Site(value);
        }
    } //set_Site

    // This method can be used to retrieve an Image from a block 
    // of Base64-encoded text.
    private Image DeserializeFromBase64Text(String text)
    {
        Image img = null;
        ubyte memBytes[] = Convert.FromBase64String(text);
        IFormatter formatter = new BinaryFormatter();
        MemoryStream stream = new MemoryStream(memBytes);
        img = (Image)(formatter.Deserialize(stream));
        stream.Close();
        return img;
    } //DeserializeFromBase64Text
} //PropertyUIComponent

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: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft