【发布时间】:2011-10-25 21:24:08
【问题描述】:
当我将控件添加到表单时,它会正常运行,直到我尝试指定一个大于 int16.MaxValue 的位置。控件只是堆叠在一起。这是经过简化但演示了行为的代码:
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);
}
}
我想避免以编程方式移动滚动条,因为这会导致时间问题。
您对如何解决此问题有任何想法吗? TIA。
【问题讨论】:
-
我运行了您的代码,似乎工作正常。有什么问题?
-
如果向下滚动到底部,则只有 425 个文本框可见。是的,当我溢出 int.MinValue. 时,我希望至少有一个异常。
-
但我在最后一个文本框中看到 499 :(
-
我运行的是 64 位的 Windows7。 Serge 说有不同的行为——你在跑什么?
-
这和
Int16.MaxValue有什么关系?
标签: c# winforms controls scroll