Adding dynamic controls to form with auto scroll

2019-08-29 13:29发布

When I add my controls to the form, it goes fine until I try to specify a location larger than int16.MaxValue. The controls just pile up on top of each other. Here is code which is simplified but demonstrates the behavior:

private void Form1_Load(object sender, EventArgs e)
{
    this.AutoScroll = true;
    int nexttop = 0;
    for (int i = 0; i < 500; i++)
    {
        TextBox t  = new TextBox();
        t.Text = i.ToString();
        t.Multiline = true;
        if (nexttop > Int16.MaxValue)
        {
            bool debug = true;
        }
        t.Location = new Point(0, nexttop);
        t.Size = new Size(100, 77);
        nexttop += t.Height;
        this.Controls.Add(t);
    }
}

I want to avoid moving the scroll bar programaticaly, since this causes timing issues.

Do you have any ideas on how to fix this? TIA.

1条回答
别忘想泡老子
2楼-- · 2019-08-29 14:01

This limit (32767) is due to GDI+. I believe different behaviours may be observed according to the Windows version.

查看更多
登录 后发表回答