3
我想創建一個自定義可摺疊面板用於我的項目之一。我設置它來顯示哪些邊應該能夠摺疊,並且它需要一個字符串輸入{"None", "Up", "Right", "Down", "Left", "All"};
。c#usercontrol設置自定義屬性的選項列表
這是我到目前爲止有:
public partial class CollapsiblePanel : UserControl
{
# region Collapse Direction
List<string> DirectionOptions = new List<string> { "None", "Up", "Right", "Down", "Left", "All" };
[Browsable(true), DefaultValue("All"), Description("Direction panel collapses. 0-none, 1-up, 2-right, 3-down, 4-left, 5-all")]
[ListBindable(true), Editor(typeof(ComboBox), typeof(UITypeEditor))]
private string _direction = "All";
public List<string> Direction
{
get { return DirectionOptions; }
set
{
DirectionOptions = value;
callCollapseDirectionChanged();
}
}
public event Action CollapseDirectionChanged;
protected void callCollapseDirectionChanged()
{
Action handler = CollapseDirectionChanged;
DisplayButtons();
if (handler != null)
{
handler();
}
}
# endregion
public CollapsiblePanel()
{
InitializeComponent();
}
private void DisplayButtons()
{
switch (_direction)
{
case "None":
buttonDown.Visible = false;
buttonUp.Visible = false;
buttonRight.Visible = false;
buttonLeft.Visible = false;
break;
case "Up":
buttonDown.Visible = false;
buttonUp.Visible = true;
buttonRight.Visible = false;
buttonLeft.Visible = false;
break;
case "Right":
buttonDown.Visible = false;
buttonUp.Visible = false;
buttonRight.Visible = true;
buttonLeft.Visible = false;
break;
case "Down":
buttonDown.Visible = true;
buttonUp.Visible = false;
buttonRight.Visible = false;
buttonLeft.Visible = false;
break;
case "Left":
buttonDown.Visible = false;
buttonUp.Visible = false;
buttonRight.Visible = false;
buttonLeft.Visible = true;
break;
case "All":
buttonDown.Visible = true;
buttonUp.Visible = true;
buttonRight.Visible = true;
buttonLeft.Visible = true;
break;
}
}
}
有人能向我解釋如何讓設計師賦予用戶DirectionOptions
列表作爲可能的值?他們可以選擇任何一個字符串作爲值。
非常感謝。這就是它。 – Chris