Language

IPropertyValueUIService インターフェイス

定義

プロパティ ブラウザーに表示されるコンポーネントのプロパティのイメージ、ツールヒント、およびイベント ハンドラーを管理するためのインターフェイスを提供します。

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

例

次のコード例では、 IPropertyValueUIService インターフェイスのインスタンスを取得し、サービスに PropertyValueUIHandler を追加するコンポーネントを作成します。 ハンドラーは、PropertyValueUIItem または HorizontalMargin という名前のコンポーネントのすべてのプロパティに対してVerticalMargin オブジェクトを提供します。 これらのプロパティの PropertyValueUIItem は、イメージ、ツールヒント、およびプロパティのイメージがクリックされたときにメッセージ ボックスを表示するイベント ハンドラーを提供します。 グリッドにコンポーネントのこれらのプロパティが表示されている場合、イメージとツールヒントは PropertyGrid に表示されます。

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

注釈

コンポーネントは、 IPropertyValueUIService インターフェイスを使用して、コンポーネントの任意のプロパティに PropertyValueUIItem オブジェクトを提供できます。 プロパティに関連付けられている PropertyValueUIItem は、プロパティに関連付けられたイメージがクリックされたときに発生するイベントのイメージ、ツールヒント、およびイベント ハンドラーを提供できます。

IPropertyValueUIService インターフェイスには、内部リストとの間でデリゲートPropertyValueUIHandler追加、削除、および取得するメソッドが用意されています。 コンポーネントのプロパティがプロパティ ブラウザーに表示されると、リスト内の各 PropertyValueUIHandler に、コンポーネントの各プロパティに PropertyValueUIItem を提供できます。

オブジェクトのプロパティを表示するようにプロパティ ブラウザーを設定すると、コンポーネントの各プロパティに対してこのインターフェイスの GetPropertyUIValueItems メソッドが呼び出され、プロパティを表す PropertyDescriptor が渡されます。 GetPropertyUIValueItems メソッドは、サービスに追加された各PropertyValueUIHandlerを呼び出します。 各PropertyValueUIHandlerは、PropertyValueUIItem パラメーターで渡されたArrayList パラメーターにvalueUIItemListを追加して、PropertyDescriptor パラメーターで渡されたpropDescで表されるプロパティの UI 項目を指定できます。

PropertyValueUIItemには、プロパティ名の横に表示するイメージ、ツールヒント文字列、およびプロパティに関連付けられているイメージがダブルクリックされたときに呼び出すイベント ハンドラーを含めることができます。

メソッド

名前 説明
AddPropertyValueUIHandler(PropertyValueUIHandler)

指定した PropertyValueUIHandler をこのサービスに追加します。

GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor)

指定したコンテキストとプロパティ記述子の特性に一致する PropertyValueUIItem オブジェクトを取得します。

NotifyPropertyValueUIItemsChanged()

IPropertyValueUIService オブジェクトのグローバル リストが変更されたことをPropertyValueUIItem実装に通知します。

RemovePropertyValueUIHandler(PropertyValueUIHandler)

指定した PropertyValueUIHandler をプロパティ値 UI サービスから削除します。

イベント

名前 説明
PropertyUIValueItemsChanged

PropertyValueUIItem オブジェクトの一覧が変更されたときに発生します。

適用対象

こちらもご覧ください