Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / ImageIndexEditor.cs / 1 / ImageIndexEditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Windows.Forms.Design.ImageIndexEditor..ctor()")]
namespace System.Windows.Forms.Design {
using System.Runtime.Serialization.Formatters;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Design;
using System.ComponentModel.Design;
using Microsoft.Win32;
using System.Windows.Forms.Design;
using System.Windows.Forms.ComponentModel;
///
///
/// Provides an editor for visually picking an image index.
///
internal class ImageIndexEditor : UITypeEditor {
protected ImageList currentImageList;
protected PropertyDescriptor currentImageListProp;
protected object currentInstance;
protected UITypeEditor imageEditor;
protected string parentImageListProperty = "Parent";
protected string imageListPropertyName = null;
///
///
/// Initializes a new instance of the class.
///
public ImageIndexEditor() {
// Get the type editor for images. We use the properties on
// this to determine if we support value painting, etc.
//
imageEditor = (UITypeEditor)TypeDescriptor.GetEditor(typeof(Image), typeof(UITypeEditor));
}
internal UITypeEditor ImageEditor {
get { return imageEditor; }
}
internal string ParentImageListProperty {
get {
return parentImageListProperty;
}
}
///
///
/// Retrieves an image for the current context at current index.
///
protected virtual Image GetImage(ITypeDescriptorContext context, int index, string key, bool useIntIndex) {
Image image = null;
object instance = context.Instance;
if(instance is object[]) { // we would not know what to do in this case anyway (i.e. multiple selection of objects)
return null;
}
// If the instances are different, then we need to re-aquire our image list.
//
if ((index >= 0) || (key != null)) {
if (currentImageList == null ||
instance != currentInstance ||
(currentImageListProp != null && (ImageList)currentImageListProp.GetValue(currentInstance) != currentImageList)) {
currentInstance = instance;
// first look for an attribute
PropertyDescriptor imageListProp = ImageListUtils.GetImageListProperty(context.PropertyDescriptor, ref instance);
// not found as an attribute, do the old behavior
while(instance != null && imageListProp == null) {
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(instance);
foreach (PropertyDescriptor prop in props) {
if (typeof(ImageList).IsAssignableFrom(prop.PropertyType)) {
imageListProp = prop;
break;
}
}
if (imageListProp == null) {
// We didn't find the image list in this component. See if the
// component has a "parent" property. If so, walk the tree...
//
PropertyDescriptor parentProp = props[ParentImageListProperty];
if (parentProp != null) {
instance = parentProp.GetValue(instance);
}
else {
// Stick a fork in us, we're done.
//
instance = null;
}
}
}
if (imageListProp != null) {
currentImageList = (ImageList)imageListProp.GetValue(instance);
currentImageListProp = imageListProp;
currentInstance = instance;
}
}
if (currentImageList != null) {
if (useIntIndex) {
if (currentImageList != null && index < currentImageList.Images.Count) {
index = (index > 0) ? index : 0;
image = currentImageList.Images[index];
}
}
else {
image = currentImageList.Images[key];
}
}
else {
// no image list, no image
image = null;
}
}
return image;
}
///
///
/// Gets a value indicating whether this editor supports the painting of a representation
/// of an object's value.
///
public override bool GetPaintValueSupported(ITypeDescriptorContext context) {
if (imageEditor != null) {
return imageEditor.GetPaintValueSupported(context);
}
return false;
}
///
///
///
/// Paints a representative value of the given object to the provided
/// canvas. Painting should be done within the boundaries of the
/// provided rectangle.
///
///
public override void PaintValue(PaintValueEventArgs e) {
if (ImageEditor != null){
Image image = null;
if (e.Value is int) {
image = GetImage(e.Context, (int)e.Value, null, true);
}
else if (e.Value is string) {
image = GetImage(e.Context, -1, (string)e.Value, false);
}
if (image != null) {
ImageEditor.PaintValue(new PaintValueEventArgs(e.Context, image, e.Graphics, e.Bounds));
}
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebProxyScriptElement.cs
- TrackBarDesigner.cs
- DataService.cs
- UpdateProgress.cs
- LicFileLicenseProvider.cs
- DataServiceQuery.cs
- AttributeEmitter.cs
- SettingsSavedEventArgs.cs
- TemplateControlBuildProvider.cs
- XPathDocumentNavigator.cs
- NavigatingCancelEventArgs.cs
- CustomErrorsSection.cs
- UriTemplateQueryValue.cs
- PeerApplication.cs
- WebGetAttribute.cs
- ClientApiGenerator.cs
- EqualityComparer.cs
- MarshalByRefObject.cs
- IdentityNotMappedException.cs
- MdiWindowListStrip.cs
- ArrayListCollectionBase.cs
- SystemIPAddressInformation.cs
- TreeNode.cs
- KeyboardNavigation.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- PropertyNames.cs
- CacheModeValueSerializer.cs
- AmbiguousMatchException.cs
- UnSafeCharBuffer.cs
- TabPanel.cs
- TrackingServices.cs
- NullableConverter.cs
- EventManager.cs
- SettingsBindableAttribute.cs
- DataViewManager.cs
- RegisteredArrayDeclaration.cs
- Base64Encoder.cs
- initElementDictionary.cs
- AttachedAnnotationChangedEventArgs.cs
- RecordManager.cs
- MimeTypeAttribute.cs
- ParenthesizePropertyNameAttribute.cs
- DataControlPagerLinkButton.cs
- ProcessStartInfo.cs
- ChannelTokenTypeConverter.cs
- SQLInt16Storage.cs
- Currency.cs
- HostedHttpTransportManager.cs
- GridItemProviderWrapper.cs
- ObjectRef.cs
- DataRecordInternal.cs
- MaskDesignerDialog.cs
- DbDeleteCommandTree.cs
- XmlChildNodes.cs
- RuleElement.cs
- _HTTPDateParse.cs
- ListControl.cs
- MemoryFailPoint.cs
- ToolStripControlHost.cs
- RepeaterCommandEventArgs.cs
- StopStoryboard.cs
- DesignerLoader.cs
- PrintEvent.cs
- XmlDataSource.cs
- ComponentResourceKey.cs
- XmlSerializerVersionAttribute.cs
- KeyNotFoundException.cs
- ServiceDescriptionReflector.cs
- TextRunCache.cs
- ObjectTag.cs
- MemoryMappedFileSecurity.cs
- FieldToken.cs
- PrincipalPermission.cs
- PageCodeDomTreeGenerator.cs
- SessionEndingEventArgs.cs
- ForEachDesigner.xaml.cs
- DashStyles.cs
- GorillaCodec.cs
- AppliedDeviceFiltersDialog.cs
- DrawingContextFlattener.cs
- PerfService.cs
- ToolTip.cs
- FillBehavior.cs
- WSTrustFeb2005.cs
- cookieexception.cs
- listitem.cs
- TrustLevelCollection.cs
- ProcessHostMapPath.cs
- CallSiteBinder.cs
- XhtmlBasicCommandAdapter.cs
- TableLayoutPanelBehavior.cs
- DataSourceXmlSerializer.cs
- ReadWriteControlDesigner.cs
- ObservableDictionary.cs
- ColorContext.cs
- SystemPens.cs
- CategoryGridEntry.cs
- MarkedHighlightComponent.cs
- CodeDOMUtility.cs
- ListViewItemSelectionChangedEvent.cs