I’m just learning about custom controls in C# (window forms) I’ve created the below custom control, as you can see I have a propery called “Test” that should be set to an enum value of EnumTest – it’s working find, except what I would like is for the user of the control to select more than one property so the “Test” property can be:
Test = EnumTest.TopLeft | EnumTest.TopRight;
Is this possible – and if so, how as the drop down box in properties only allows me to select one enum in the list. Also if possible I need to detect that if the user set it to “None” then it would be a single choice rather than multi choice.
namespace WindowsFormsApplication1
{
public partial class myControl1 : Control
{
public enum EnumTest
{
None = 0,
TopLeft = 1,
TopRight = 2,
BottomLeft = 4,
BottomRight = 8,
All = TopLeft | TopRight | BottomLeft | BottomRight
}
public UserControl1() {
InitializeComponent();
}
public EnumTest Test {
get;
set;
}
}
}
Many thanks for any help on this.
Add
[Flags]to your enum to indicate that it accepts multiple values.I don’t remember whether the property grid is aware of
[Flags]enums; if not, you’ll need to write a UITypeEditor.