0
我正在使用vs2012(C#)爲我的應用程序,我正在尋找一種方法將標籤和文本框添加到我的窗體上的tabPage中。但是由於要添加的控件數量可能大於10,我還試圖將它們添加到「列」中,以便容器控件只能水平滾動,而不是垂直滾動。根據容器高度動態添加控件的「列」
舉例來說,我試圖做這樣的事情:
LabelControl LabelControl LabelControl LabelControl
TextboxControl TextboxControl TextboxControl TextboxControl
LabelControl LabelControl LabelControl LabelControl
TextboxControl TextboxControl TextboxControl TextboxControl
etc.
「容器」控制是一個TabPage的,所以我知道我必須抓住從高度和使用它。我能夠獲取文本框進行渲染,但是在頂部的標籤控件,以及下面的文本框中遇到困難。
這裏是我到目前爲止有:
int height = tabPageBicycle.Height;
Point startLocation = new Point(0, 0);
int previousX = 0;
int previousY = 0;
int currentX = 0;
for (int x = 0; x < 75; x++)
{
Label label = new Label();
TextEdit text = new TextEdit();
label.Text = x.ToString();
text.Text = x.ToString();
label.Location = new Point(currentX, previousY);
tabPageBicycle.Controls.Add(label);
if ((height - previousY) < text.Height)
{
currentX += 100;
previousY = 0;
}
text.Location = new Point(currentX + text.Height + 5, previousY + 50);
previousX = text.Location.X;
previousY = text.Location.Y;
tabPageBicycle.Controls.Add(text);
}
任何線索,我在做什麼錯?