IPropertyValueUIService 介面
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供介面管理物件屬性瀏覽器中顯示的元件屬性的圖片、工具提示及事件處理程序。
public interface class IPropertyValueUIService
public interface IPropertyValueUIService
type IPropertyValueUIService = interface
Public Interface IPropertyValueUIService
範例
以下程式碼範例建立一個元件,取得介面實例 IPropertyValueUIService 並將 a PropertyValueUIHandler 加入服務。 處理器提供 PropertyValueUIItem 一個物件,用於包含名為 HorizontalMargin 或 VerticalMargin的元件屬性。
PropertyValueUIItem for these properties 提供一張圖片、一個工具提示,以及一個事件處理程序,當點擊該屬性的圖片時會顯示訊息框。 當網格顯示元件的這些屬性時,圖片和工具提示會顯示在 a 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 屬性都有機會為該元件的每個屬性提供 a PropertyValueUIItem 。
當屬性瀏覽器設定為顯示物件屬性時,會呼叫GetPropertyUIValueItems該介面的方法,針對該元件的每個屬性,傳遞代表該屬性的 。PropertyDescriptor 該方法呼叫 GetPropertyUIValueItems 每個 PropertyValueUIHandler 已加入服務的程式。 每個PropertyValueUIHandler參數都可以在參數中傳遞的參數PropertyValueUIItem中加入 a ArrayListvalueUIItemList,以提供該參數所代表PropertyDescriptorpropDesc屬性的 UI 項目。
A PropertyValueUIItem 可以包含一張圖片,用於在屬性名稱旁顯示,一個工具提示字串,以及一個事件處理程序,當雙擊與屬性相關的圖片時呼叫。
方法
| 名稱 | Description |
|---|---|
| AddPropertyValueUIHandler(PropertyValueUIHandler) |
為此服務新增指定 PropertyValueUIHandler 內容。 |
| GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor) |
取得 PropertyValueUIItem 符合指定上下文與屬性描述符特徵的物件。 |
| NotifyPropertyValueUIItemsChanged() |
通知實 IPropertyValueUIService 作全域物件清單 PropertyValueUIItem 已被修改。 |
| RemovePropertyValueUIHandler(PropertyValueUIHandler) |
將指定 PropertyValueUIHandler 內容從屬性值 UI 服務中移除。 |
事件
| 名稱 | Description |
|---|---|
| PropertyUIValueItemsChanged |
當物件清單 PropertyValueUIItem 被修改時會發生。 |