您需要設置列和行的PictureBoxes應坐下:
for (int i = 0, r = 0; i < dt.Rows.Count; i++, r++)
{
int maxCol = tableLayoutPanel1.ColumnCount - 1;
PictureBox pb = new PictureBox();
pb.ImageLocation = ../imagesDT/answered.gif
tableLayoutPanel1.Controls.Add(pb);
tableLayoutPanel1.SetRow(pb, i);
tableLayoutPanel1.SetColumn(pb, maxCol);
}
你可以得到列的寬度和行高地這樣的:
var widths = tableLayoutPanel1.GetColumnWidths();
var heights = tableLayoutPanel1.GetRowHeights();
你可以通過設置邊距來微調位置,例如:
pb.Margin = New Padding(50, 20, 0, 0);
要改變He行ights您可以使用設計器或者你可以在每一行的RowStyle設置其身高:
tableLayoutPanel1.RowStyles[row].SizeType = SizeType.Absolute;
tableLayoutPanel1.RowStyles[row].Height = newHeight;
爲了讓您在您的測試表佈局可見,你可能想在插入這樣的代碼CellPaint
事件:
private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
Random R = new Random(1 + e.Row * 3 + e.Column * 7);
using (SolidBrush brush = new SolidBrush(
Color.FromArgb(99, Color.FromArgb(R.Next(123456789)))))
e.Graphics.FillRectangle(brush, e.CellBounds);
}
來源
2014-09-05 11:24:25
TaW
你解決了你的問題嗎? – TaW 2014-09-09 13:55:38
工作,但不完全是我所需要的。在圖像之前,它們將是兩個標籤,第二個標籤文本會到另一個行,當我將圖像放置在右側時,所有文本流都會丟失。@ TaW – user2837291 2014-09-10 06:30:03
也許您應該1)告訴我們表格的佈局(數量列)和2)包括現在看起來像的新形象。 Yopu將不得不按照正確的順序添加所有控件,並且不會留下任何空白或設置右列和可能的行位置。 – TaW 2014-09-10 07:11:56