[英]Is there a WinForms control to show and hide another WinForms control?
是否有一个WinForms
控件可以显示和隐藏另一个类似于TreeNode
折叠按钮概念的WinForms控件?
最简单的方法是在表单中添加按钮和复选框,为复选框CheckedChanged事件添加事件处理程序,然后在事件处理程序代码中简单地添加:
button1.Visible = !checkBox1.Checked;
更好的方法是使用数据绑定和INotifyProperyChanged
您的意思类似于Accordian吗?
看到这篇文章winforms手风琴
您可以为要使用的所有控件编写包装器,并使它们的可见性取决于另一个控件的状态。
private delegate void ToggleVoid();
private static event ToggleVoid VisibilityToggle;
private void Form1_Load(object sender, EventArgs e)
{
DependantButton TestButton = new DependantButton();
TestButton.SetBounds(100, 100, 100, 100);
this.Controls.Add(TestButton);
Button ToggleButton = new Button();
ToggleButton.SetBounds(200, 200, 100, 100);
ToggleButton.Click += OnToggleButtonClicked;
this.Controls.Add(ToggleButton);
}
private void OnToggleButtonClicked(object sender, EventArgs e)
{
VisibilityToggle.Invoke();
}
private class DependantButton : Button
{
public DependantButton() : base()
{
VisibilityToggle += ToggleVisibility;
}
public void ToggleVisibility()
{
Visible = !Visible;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.