【发布时间】:2011-09-05 14:24:49
【问题描述】:
我刚刚学习 C# 中的自定义控件(窗口窗体)我创建了以下自定义控件,如您所见,我有一个名为“Test”的属性,它应该设置为 EnumTest 的枚举值 - 它是工作查找,除了我希望控件的用户选择多个属性,因此“测试”属性可以是:
Test = EnumTest.TopLeft | EnumTest.TopRight;
这可能吗 - 如果是这样,属性中的下拉框如何只允许我在列表中选择一个枚举。此外,如果可能的话,我需要检测到如果用户将其设置为“无”,那么它将是单选而不是多选。
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;
}
}
}
非常感谢您对此提供的任何帮助。
【问题讨论】:
标签: c# winforms enums controls