如何实现可折叠控件 [英] How to implement the collapsible control

查看:69
本文介绍了如何实现可折叠控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请建议控制,可见,将容器中的其他组件移开,当它被隐藏时挤压它占据的地方



我是什么尝试过:



FlowLayoutPanel不是很有用的方法

please suggest the control, being visible, to move apart other components in container and when it's being hided to squeeze the place it occupies

What I have tried:

FlowLayoutPanel is not pretty useful methinks

推荐答案

对于Winforms你可以使用类似这样的东西:

For Winforms you can use something like this:
public Form9()
{
    InitializeComponent();

    var button1 = new Button();
    var button2 = new Button();
    var button3 = new Button();

    // Needs a flowLayoutPanel on your Form.
    this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
    this.flowLayoutPanel1.BackColor = Color.Brown;
    this.flowLayoutPanel1.Controls.Add(button1);
    this.flowLayoutPanel1.Controls.Add(button2);
    this.flowLayoutPanel1.Controls.Add(button3);

    button1.Click += ButtonCollapse;
    button2.Click += ButtonCollapse;
    button3.Click += ButtonCollapse;
}

private void ButtonCollapse(object sender, EventArgs e)
{
    var btn = (Button)sender;

    if (btn.Tag == null)
    {
        btn.Height /= 2;
        btn.Tag = "collapsed";
    }
    else
    {
        btn.Height *= 2;
        btn.Tag = null;
    }
}


这篇关于如何实现可折叠控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆