views:

22

answers:

1

I make new project and simplified it to check if this bug is real, and this is my code:

    private void button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            groupBox1.Height += 1;
            Thread.Sleep(100);
        }
    }
    private void button2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            textBox1.Height += 1;
            Thread.Sleep(100);
        }
    }

Put on form 2 buttons, groupBox and textBox, and watch how textBox smoothly change between iterations, and groupBox change after loop ends. Why this is happening?

I tested it on .NET 2.0 and 3.5 - same effect.

+1  A: 

I don't know the underlying reason why the GroupBox behaves differently from TextBox or Panel, but it might have to do with the fact that GroupBox is used as a container control but doesn't actually inherit from any container types. Panel inherits from ScrollableControl, which might add some additional layout logic.

If the concern is just getting it to grow smoothly, you can add groupBox1.Refresh(); to your code to accomplish this.

CodeSavvyGeek