internal void PopulateHandle() { for (int i = 0; i < this.list.Count; i++) { ImageListImage image = (ImageListImage)this.list[i]; this.owner.ImageList.Images.Add(image.Name, image.Image); } }
private ImageListImage LoadImageFromStream(Stream stream, bool imageIsIcon) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); MemoryStream stream2 = new MemoryStream(buffer); return(ImageListImage.ImageListImageFromStream(stream2, imageIsIcon)); }
private static ImageListImage LoadImageFromStream(Stream stream, bool imageIsIcon) { // Copy the original stream to a buffer, then wrap a memory stream around it to avoid locking the file. byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); // The created image will take over ownership of the stream. MemoryStream ms = new MemoryStream(buffer); return(ImageListImage.ImageListImageFromStream(ms, imageIsIcon)); }
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); using (MemoryStream ms = new MemoryStream(buffer)) { return(ImageListImage.ImageListImageFromStream(ms, imageIsIcon)); } }
public int Add(ImageListImage value) { int num = this.list.Add(value); if (value.Name != null) { this.owner.ImageList.Images.Add(value.Name, value.Image); return(num); } this.owner.ImageList.Images.Add(value.Image); return(num); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { ArrayList list = new ArrayList(); if (provider == null) { return(value); } if (((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService))) != null) { if (this.fileDialog == null) { this.fileDialog = new OpenFileDialog(); this.fileDialog.Multiselect = true; string str = ImageEditor.CreateFilterEntry(this); for (int i = 0; i < this.GetImageExtenders().Length; i++) { ImageEditor o = (ImageEditor)Activator.CreateInstance(this.GetImageExtenders()[i], BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null); System.Type type = base.GetType(); System.Type type2 = o.GetType(); if ((!type.Equals(type2) && (o != null)) && type.IsInstanceOfType(o)) { str = str + "|" + ImageEditor.CreateFilterEntry(o); } } this.fileDialog.Filter = str; } IntPtr focus = System.Design.UnsafeNativeMethods.GetFocus(); try { if (this.fileDialog.ShowDialog() != DialogResult.OK) { return(list); } foreach (string str2 in this.fileDialog.FileNames) { FileStream stream = new FileStream(str2, FileMode.Open, FileAccess.Read, FileShare.Read); ImageListImage image = this.LoadImageFromStream(stream, str2.EndsWith(".ico")); image.Name = Path.GetFileName(str2); list.Add(image); } } finally { if (focus != IntPtr.Zero) { System.Design.UnsafeNativeMethods.SetFocus(new HandleRef(null, focus)); } } } return(list); }
protected override object[] GetItems(object editValue) { if (editValue is not ImageList.ImageCollection source) { return(base.GetItems(editValue)); } var imageListImages = new ImageListImage[source.Count]; for (int i = 0; i < source.Count; i++) { imageListImages[i] = new ImageListImage(source[i]) { Name = source.Keys[i] }; } return(imageListImages); }
public bool Contains(ImageListImage value) { return this.list.Contains(value.Image); }
public void AddRange(ImageListImage[] values) { if (values == null) { throw new ArgumentNullException("values"); } foreach (ImageListImage image in values) { if (image != null) { this.Add(image); } } }
public int Add(ImageListImage value) { int num = this.list.Add(value); if (value.Name != null) { this.owner.ImageList.Images.Add(value.Name, value.Image); return num; } this.owner.ImageList.Images.Add(value.Image); return num; }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider is null) { return(value); } var images = new ArrayList(); if (!provider.TryGetService(out IWindowsFormsEditorService editorService)) { return(images); } if (_fileDialog is null) { _fileDialog = new OpenFileDialog { Multiselect = true }; string filter = CreateFilterEntry(this); foreach (Type extender in GetImageExtenders()) { var myClass = GetType(); var editor = (ImageEditor)Activator.CreateInstance( extender, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, binder: null, args: null, culture: null); var editorClass = editor.GetType(); if (!myClass.Equals(editorClass) && editor is not null && myClass.IsInstanceOfType(editor)) { filter += $"|{CreateFilterEntry(editor)}"; } } _fileDialog.Filter = filter; } IntPtr hwndFocus = User32.GetFocus(); try { if (_fileDialog.ShowDialog() == DialogResult.OK) { foreach (string name in _fileDialog.FileNames) { using FileStream file = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read); ImageListImage image = LoadImageFromStream(file, name.EndsWith(".ico")); image.Name = Path.GetFileName(name); images.Add(image); } } } finally { if (hwndFocus != IntPtr.Zero) { User32.SetFocus(hwndFocus); } } return(images); }
public bool Contains(ImageListImage value) { return(this.list.Contains(value.Image)); }