IPropertyValueUIService Gränssnitt
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Tillhandahåller ett gränssnitt för att hantera avbildningar, knappbeskrivningar och händelsehanterare för egenskaperna för en komponent som visas i en egenskapswebbläsare.
public interface class IPropertyValueUIService
public interface IPropertyValueUIService
type IPropertyValueUIService = interface
Public Interface IPropertyValueUIService
Exempel
I följande kodexempel skapas en komponent som hämtar en instans av IPropertyValueUIService gränssnittet och lägger till en PropertyValueUIHandler i tjänsten. Hanteraren tillhandahåller ett PropertyValueUIItem objekt för alla egenskaper för komponenten med namnet HorizontalMargin eller VerticalMargin. För PropertyValueUIItem dessa egenskaper finns en bild, en knappbeskrivning och en händelsehanterare som visar en meddelanderuta när bilden för egenskapen klickas. Bilden och knappbeskrivningen visas i en PropertyGrid när rutnätet visar dessa egenskaper för komponenten.
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;
}
}
}
}
}
Kommentarer
En komponent kan använda IPropertyValueUIService gränssnittet för att tillhandahålla PropertyValueUIItem objekt för alla egenskaper för komponenten. En PropertyValueUIItem associerad med en egenskap kan tillhandahålla en avbildning, en knappbeskrivning och en händelsehanterare för händelsen som genereras när avbildningen som är associerad med egenskapen klickas.
Gränssnittet IPropertyValueUIService innehåller metoder för att lägga till, ta bort och hämta PropertyValueUIHandler ombud till eller från en intern lista. När egenskaperna för en komponent visas i en egenskapswebbläsare ges var och PropertyValueUIHandler en i listan möjlighet att tillhandahålla en PropertyValueUIItem för varje egenskap för komponenten.
När en egenskapswebbläsare är inställd på att visa egenskaperna för ett objekt anropas GetPropertyUIValueItems metoden för det här gränssnittet för varje egenskap för komponenten och skickar en PropertyDescriptor som representerar egenskapen. Metoden GetPropertyUIValueItems anropar var och en PropertyValueUIHandler som har lagts till i tjänsten. Var och PropertyValueUIHandler en kan lägga till en PropertyValueUIItem i parametern ArrayList som skickas i parametern valueUIItemList för att ange användargränssnittsobjekt för egenskapen som representeras av den PropertyDescriptor skickade parametern propDesc .
En PropertyValueUIItem kan innehålla en bild som ska visas bredvid egenskapsnamnet, en Knappbeskrivningssträng och en händelsehanterare som ska anropas när en bild som är associerad med egenskapen dubbelklickas.
Metoder
| Name | Description |
|---|---|
| AddPropertyValueUIHandler(PropertyValueUIHandler) |
Lägger till den angivna PropertyValueUIHandler i den här tjänsten. |
| GetPropertyUIValueItems(ITypeDescriptorContext, PropertyDescriptor) |
Hämtar de PropertyValueUIItem objekt som matchar de angivna egenskaperna för kontext och egenskapsbeskrivning. |
| NotifyPropertyValueUIItemsChanged() |
Meddelar implementeringen IPropertyValueUIService att den globala listan över PropertyValueUIItem objekt har ändrats. |
| RemovePropertyValueUIHandler(PropertyValueUIHandler) |
Tar bort den angivna PropertyValueUIHandler från UI-tjänsten för egenskapsvärdet. |
Händelser
| Name | Description |
|---|---|
| PropertyUIValueItemsChanged |
Inträffar när listan över PropertyValueUIItem objekt ändras. |