| | 1 | | using PropertyGridHelpers.Controls; |
| | 2 | | using System; |
| | 3 | | using System.ComponentModel; |
| | 4 | | using System.Drawing.Design; |
| | 5 | | using System.Windows.Forms; |
| | 6 | |
|
| | 7 | | namespace PropertyGridHelpers.UIEditors |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// A generic <see cref="UITypeEditor"/> for editing flag-style enums in a <see cref="PropertyGrid"/>, |
| | 11 | | /// with support for customized display text using a specified <see cref="EnumConverter"/>. |
| | 12 | | /// </summary> |
| | 13 | | /// <typeparam name="T"> |
| | 14 | | /// The <see cref="EnumConverter"/> type used to convert enum values to user-friendly display text. |
| | 15 | | /// Must have a parameterless constructor. |
| | 16 | | /// </typeparam> |
| | 17 | | /// <remarks> |
| | 18 | | /// This editor uses a <see cref="FlagCheckedListBox"/> hosted in a dropdown and allows |
| | 19 | | /// multiple values to be selected for enums decorated with the <see cref="FlagsAttribute"/>. |
| | 20 | | /// |
| | 21 | | /// The generic parameter <typeparamref name="T"/> allows you to specify a custom converter, |
| | 22 | | /// such as <see cref="Converters.EnumTextConverter{TEnum}"/>, to localize or stylize enum values. |
| | 23 | | /// |
| | 24 | | /// Example: |
| | 25 | | /// <code> |
| | 26 | | /// [Editor(typeof(FlagEnumUIEditor<EnumTextConverter<MyEnum>>), typeof(UITypeEditor))] |
| | 27 | | /// [TypeConverter(typeof(EnumTextConverter<MyEnum>))] |
| | 28 | | /// public MyEnum Options { get; set; } |
| | 29 | | /// </code> |
| | 30 | | /// </remarks> |
| | 31 | | /// <seealso cref="DropDownVisualizer{FlagCheckedListBox}"/> |
| | 32 | | /// <seealso cref="FlagEnumUIEditor"/> |
| | 33 | | /// <seealso cref="FlagCheckedListBox"/> |
| | 34 | | /// <seealso cref="Converters.EnumTextConverter{T}"/> |
| | 35 | | public partial class FlagEnumUIEditor<T> |
| | 36 | | : DropDownVisualizer<FlagCheckedListBox> |
| | 37 | | where T : EnumConverter, new() |
| | 38 | | { |
| | 39 | | /// <summary> |
| | 40 | | /// Initializes a new instance of the <see cref="FlagEnumUIEditor" /> class. |
| | 41 | | /// </summary> |
| 16 | 42 | | public FlagEnumUIEditor() : base() => |
| 16 | 43 | | DropDownControl.Converter = new T(); |
| | 44 | | } |
| | 45 | | } |