我正在尝试为我的一个项目创建一个自定义折叠面板。我已经设置好显示哪些边框可以折叠,并且它接受一个字符串输入{"None", "Up", "Right", "Down", "Left", "All"}
。
以下是我目前的代码:
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
列表作为可能的值提供给用户吗?他们可以选择任意一个字符串作为值。
public event Action CollapseDirectionChanged;
这个部分,我对这里的所有内容都理解。在 void 方法之前,它实际上是做什么的?如果没有它,你能让这段代码工作吗? - IneffaWolf