wolen
10-12-2012 15:21:18
Hi, I have troubles with TableLayoutPanel (2 troubles). I want to make this layoutPanel with 2 column and some rows (could be more then 2). I tried this code and it works. BUT when I have 3 rows so I get exception...out of range. How it is possible?
Second problem is scrollbars. I tried this code but scrollbar is still hidden.
It will be some stupid mistake but I want to solve mainly the first problem. I dont know how can be fisrt add to table.AddControl out of range.
any help would be appreciated =)
TableLayoutPanel table = new TableLayoutPanel();
table.Location = new Point(300, 300);
table.Size = new Size(200, 200);
table.Skin = skinDict["Panel"];
table.RowCount = 2;
table.ColumnCount = 2;
// Make sure you create the TableLayoutStyle objects, and add them to the table's column styles and row styles
// (dont need to do this for flow layout)
var colStyless = new TableLayoutStyle[table.RowCount];
var rowStyless = new TableLayoutStyle[table.ColumnCount];
for (int i = 0; i < colStyless.Length; i++)
colStyless[i] = new TableLayoutStyle(SizeType.Absolute, 70); //width
for (int i = 0; i < rowStyless.Length; i++)
rowStyless[i] = new TableLayoutStyle(SizeType.Absolute, 40); //height
table.ColumnStyles.AddRange(colStyless);
table.RowStyles.AddRange(rowStyless);
for (int i = 0; i < table.RowCount; i++) {
for (int j = 0; j < table.ColumnCount; j++) {
Button b = new Button();
b.Size = new Size(50, 50);
b.Skin = skinDict["Button"];
table.AddControl(b, i, j);
}
}
gui.Controls.Add(table);
Second problem is scrollbars. I tried this code but scrollbar is still hidden.
table.HScrollBarStyle = new ScrollBarStyle
{
Extent = 16,
ThumbStyle =
{
BorderStyle =
{
Thickness = new Thickness(2, 2, 2, 2)
}
}
};
table.VScrollBarStyle = new ScrollBarStyle
{
Extent = 12,
ThumbStyle =
{
BorderStyle =
{
Thickness = new Thickness(2, 2, 2, 2)
}
}
};
It will be some stupid mistake but I want to solve mainly the first problem. I dont know how can be fisrt add to table.AddControl out of range.
any help would be appreciated =)