简体   繁体   中英

How to expand an group box when an button is clicked

I have an.exe and I need to collapse a group_box when it is not used and want to expand when a button is clicked.

As of now, I have created a group-box and its been disabled and if a button is clicked that will be enabled and now I want to change the current process that is instead of disabling I want to collapse and instead of enabling I want to expand that group_box.

As of now, for the page load:

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

You Can Also Try Something Like This For Collapse And Expand The groupbox.

    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;
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM