2 // System.Drawing.Design.IconEditor.cs
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) 2003 Martin Willemoes Hansen
9 // (C) 2003 Andreas Nahr
16 using System.ComponentModel;
17 using System.Windows.Forms;
19 namespace System.Drawing.Design
21 // LAMESPEC: Why isn't this class inherited from ImageEditor?
22 public class IconEditor : UITypeEditor
25 private OpenFileDialog openDialog;
31 protected static string CreateExtensionsString (string[] extensions, string sep)
33 if (extensions.Length > 0) {
34 StringBuilder sb = new StringBuilder();
36 sb.Append (extensions[0]);
37 for (int x = 1; x < extensions.Length - 1; x++) {
39 sb.Append (extensions[x]);
48 protected static string CreateFilterEntry (IconEditor e)
50 StringBuilder sb = new StringBuilder();
51 string ExtStr = CreateExtensionsString (e.GetExtensions(), ";");
53 sb.Append (e.GetFileDialogDescription());
54 sb.Append (" (" + ExtStr + ")" + "|");
59 public override object EditValue (ITypeDescriptorContext context,
60 IServiceProvider provider, object value)
62 openDialog = new OpenFileDialog();
63 openDialog.Title = Locale.GetText ("Open image file");
64 openDialog.CheckFileExists = true;
65 openDialog.CheckPathExists = true;
66 openDialog.Filter = CreateFilterEntry (this);
67 openDialog.Multiselect = false;
70 DialogResult result = openDialog.ShowDialog();
72 // Check the result and create a new image from the file
73 if (result == DialogResult.OK)
75 return LoadFromStream (openDialog.OpenFile());
81 public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
83 return UITypeEditorEditStyle.Modal;
86 protected virtual string[] GetExtensions()
88 return new string[] {"*.ico"};
91 protected virtual string GetFileDialogDescription()
93 return Locale.GetText ("Icon files");
96 public override bool GetPaintValueSupported (ITypeDescriptorContext context)
101 protected virtual Icon LoadFromStream (Stream stream)
103 return new Icon (stream);
106 public override void PaintValue (PaintValueEventArgs e)
108 Graphics G = e.Graphics;
110 if (e.Value != null) {
111 Image I = (Image) e.Value;
112 G.DrawImage (I, e.Bounds);
115 G.DrawRectangle (Pens.Black, e.Bounds);