单击按钮时如何展开组框

时间:2019-01-09 06:02:52

标签: c#

我有一个an.exe,我需要在不使用group_box时将其折叠,并且想要在单击按钮时将其展开。

截至目前,我已经创建了一个组合框并被禁用,如果单击了将被启用的按钮,现在我想更改当前过程而不是禁用我想折叠而不是启用我想扩展该group_box。

到目前为止,对于页面加载:

groupboxname.enabled=false;
Button click:
groupboxname.enabled=true;

1 个答案:

答案 0 :(得分:1)

您也可以尝试使用类似方法来折叠和展开组框。

    public partial class Form1 : Form
    {
        int height, width;
        bool IsFirstClick = false;
        public Form1()
        {
            InitializeComponent();

            height = groupBox1.Height;
            width = groupBox1.Width;

            groupBox1.Height = 0;
            groupBox1.Width = 0;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (!IsFirstClick)
            {
                IsFirstClick = true;
                groupBox1.Width = width;
                for (int i = 0; i < height; i++)
                {
                    groupBox1.Height = i;
                }
            }
            else
            {
                IsFirstClick = false;
                for (int i = height; i>0; i--)
                {
                    groupBox1.Height = i;
                }
                groupBox1.Width = 0;
            }
        }
    }