繁体   English   中英

在其中添加新控件时,如何动态更改groupBox的大小?

[英]How can I dynamically change the size of groupBox when I add new controls in it?

嗨,我的问题是:我动态地创建了GroupBox,并且在(我的案例中的radioButtons)中将许多控件添加到了groupbox中,我希望对这些groupbox进行动态大小调整,以便显示我插入到其中的所有RadioButtons。 我能怎么做? 这是代码:

 private void IdEnForm_Load(object sender, EventArgs e)
    {

        for (int i = 0; i < a.Count; i++)
        {

            for (int j = 0; j < a[i].Count; j++)
            {
                bool help;
                if (j == 0) help = true;
                else help = false;


                if (help)
                {

                    gb = new GroupBox();
                    gb.Text = " which Entity you want to mantain?";
                    gb.Font = new Font("Calibri", 12);
                    gb.AutoSize = true;
                    gb.Location = new Point(j * 150, (i + 1) * 100);


                }                      
                RadioButton  rb = new RadioButton();
                rb.Text=""+  a[i][j];
                rb.AutoSize = true;
                gb.Controls.Add(rb);

                this.Controls.Add(gb);

               // MessageBox.Show("" + a[i][j]);

            }
enter code here

您想要创建一个事件处理程序以在将控件添加到组框中时触发:

groupbox.ControlAdded += new ControlEventHandler( groupbox_ControlAdded );

然后添加一个处理事件的方法:

void groupbox_ControlAdded( object sender, ControlEventArgs e )
    {
        //Do Resizing here
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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