ImagePropertyEditor.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Design;
  6. using System.Linq;
  7. using System.Text;
  8. namespace HZH_Controls
  9. {
  10. public class ImagePropertyEditor : UITypeEditor
  11. {
  12. public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
  13. {
  14. //指定为模式窗体属性编辑器类型
  15. return UITypeEditorEditStyle.Modal;
  16. }
  17. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
  18. {
  19. //打开属性编辑器修改数据
  20. FrmSelectImage frm = new FrmSelectImage();
  21. if (value == null || value is Image)
  22. {
  23. if (value != null)
  24. frm.SelectImage = (Image)value;
  25. if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  26. return frm.SelectImage;
  27. else
  28. return value;
  29. }
  30. else
  31. {
  32. throw new Exception("这不是一个FontIcons类型的属性");
  33. }
  34. }
  35. }
  36. }