Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / ImageListImageEditor.cs / 1 / ImageListImageEditor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Windows.Forms.Design {
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Design;
using System.Reflection;
using System.Drawing.Design;
using System.Windows.Forms.ComponentModel;
///
///
/// Provides an editor that can perform default file searching for bitmap (.bmp)
/// files.
///
public class ImageListImageEditor : ImageEditor {
// VSWhidbey 95227: Metafile types are not supported in the ImageListImageEditor and should
// not be displayed as an option.
internal static Type[] imageExtenders = new Type[] { typeof(BitmapEditor)/*, gpr typeof(Icon), typeof(MetafileEditor)*/};
private OpenFileDialog fileDialog = null;
// VSWhidbey 95227: accessor needed into the static field so that derived classes
// can implement a different list of supported image types.
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
protected override Type[] GetImageExtenders() {
return imageExtenders;
}
///
///
/// Edits the given object value using the editor style provided by
/// GetEditorStyle. A service provider is provided so that any
/// required editing services can be obtained.
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
ArrayList images = new ArrayList();
if (provider != null) {
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc != null) {
if (fileDialog == null) {
fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
string filter = CreateFilterEntry(this);
for (int i = 0; i < GetImageExtenders().Length; i++) {
ImageEditor e = (ImageEditor) Activator.CreateInstance(GetImageExtenders()[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); //.CreateInstance();
Type myClass = this.GetType();
Type editorClass = e.GetType();
if (!myClass.Equals(editorClass) && e != null && myClass.IsInstanceOfType(e))
filter += "|" + CreateFilterEntry(e);
}
fileDialog.Filter = filter;
}
IntPtr hwndFocus = UnsafeNativeMethods.GetFocus();
try {
if (fileDialog.ShowDialog() == DialogResult.OK) {
foreach (string name in fileDialog.FileNames) {
ImageListImage image;
FileStream file = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read);
image = LoadImageFromStream(file, name.EndsWith(".ico"));
image.Name = System.IO.Path.GetFileName(name);
images.Add(image);
}
}
}
finally {
if (hwndFocus != IntPtr.Zero) {
UnsafeNativeMethods.SetFocus(new HandleRef(null, hwndFocus));
}
}
}
return images;
}
return value;
}
///
///
/// [To be supplied.]
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
protected override string GetFileDialogDescription() {
return SR.GetString(SR.imageFileDescription);
}
///
///
/// Determines if this editor supports the painting of a representation
/// of an object's value.
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
public override bool GetPaintValueSupported(ITypeDescriptorContext context) {
return true;
}
///
///
/// [To be supplied.]
///
private ImageListImage LoadImageFromStream(Stream stream, bool imageIsIcon) {
//Copy the original stream to a buffer, then wrap a
//memory stream around it. This way we can avoid
//locking the file
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
MemoryStream ms = new MemoryStream(buffer);
return (ImageListImage)ImageListImage.ImageListImageFromStream(ms, imageIsIcon);
}
///
///
///
/// Paints a representative value of the given object to the provided
/// canvas. Painting should be done within the boundaries of the
/// provided rectangle.
///
///
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust.
public override void PaintValue(PaintValueEventArgs e) {
if (e.Value is ImageListImage) {
e= new PaintValueEventArgs(e.Context, ((ImageListImage)e.Value).Image, e.Graphics, e.Bounds);
}
base.PaintValue(e);
}
}
}
// 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
- XPathPatternParser.cs
- DataColumnCollection.cs
- DrawingCollection.cs
- TransactionWaitAsyncResult.cs
- ClonableStack.cs
- DataView.cs
- PageCatalogPart.cs
- Object.cs
- OracleConnection.cs
- SQLBinaryStorage.cs
- Interlocked.cs
- TreeNodeConverter.cs
- ResizeGrip.cs
- TagMapCollection.cs
- BlobPersonalizationState.cs
- ADMembershipProvider.cs
- SafeThemeHandle.cs
- SchemaMapping.cs
- ProfileModule.cs
- BamlResourceDeserializer.cs
- NativeActivity.cs
- InkPresenterAutomationPeer.cs
- BindingObserver.cs
- X509ServiceCertificateAuthenticationElement.cs
- MatrixAnimationBase.cs
- TextSelectionProcessor.cs
- StructuralObject.cs
- IgnoreSectionHandler.cs
- ExceptionHelpers.cs
- AssertSection.cs
- ImpersonationContext.cs
- AdornerDecorator.cs
- GetPageCompletedEventArgs.cs
- ConfigurationManagerInternal.cs
- precedingsibling.cs
- FixedSOMPageConstructor.cs
- ConfigXmlComment.cs
- StandardToolWindows.cs
- DiscoveryClientDocuments.cs
- SelectionChangedEventArgs.cs
- CodeCastExpression.cs
- BindToObject.cs
- CatalogPartChrome.cs
- HttpCookieCollection.cs
- ObjectToIdCache.cs
- DataControlCommands.cs
- OracleInternalConnection.cs
- BitmapData.cs
- MeasurementDCInfo.cs
- TypeSystem.cs
- TableDetailsRow.cs
- SqlException.cs
- MultipartContentParser.cs
- ValueTypeFixupInfo.cs
- WebPartEditorCancelVerb.cs
- InstancePersistenceCommandException.cs
- XmlSchemaDocumentation.cs
- RepeatInfo.cs
- path.cs
- ButtonStandardAdapter.cs
- UnknownExceptionActionHelper.cs
- CopyOfAction.cs
- TextPattern.cs
- CryptoKeySecurity.cs
- GatewayDefinition.cs
- OperationDescription.cs
- WmpBitmapDecoder.cs
- BindingContext.cs
- ToolStripSeparator.cs
- BeginStoryboard.cs
- AutomationPatternInfo.cs
- StringUtil.cs
- DataGridViewAdvancedBorderStyle.cs
- SqlInternalConnectionSmi.cs
- DirectoryNotFoundException.cs
- SQLString.cs
- ErrorWrapper.cs
- TraceListener.cs
- XmlNodeReader.cs
- RotateTransform3D.cs
- ProtectedConfigurationSection.cs
- InkCanvasSelection.cs
- OpCodes.cs
- HtmlInputReset.cs
- XmlSchemaCollection.cs
- BamlBinaryWriter.cs
- FusionWrap.cs
- RequestCacheEntry.cs
- WhiteSpaceTrimStringConverter.cs
- IndexingContentUnit.cs
- Image.cs
- FilterRepeater.cs
- EntityDataReader.cs
- TraceSource.cs
- EventRoute.cs
- ValidatorCollection.cs
- PenLineJoinValidation.cs
- StrongNameMembershipCondition.cs
- BaseConfigurationRecord.cs
- DefaultPerformanceCounters.cs