本文介绍了通过自动滚动将动态控件添加到表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将控件添加到窗体时,它会很好,直到我尝试指定一个大于int16.MaxValue的位置。控件只是相互叠加。以下是简化的代码,但演示了行为:
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.
您对如何解决此问题有任何想法吗? TIA。
Do you have any ideas on how to fix this? TIA.
推荐答案
此限制(32767)是由于GDI +引起的。我相信根据Windows版本可能会观察到不同的行为。
This limit (32767) is due to GDI+. I believe different behaviours may be observed according to the Windows version.
这篇关于通过自动滚动将动态控件添加到表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!