C# 在表中列出了如何保持图片框的右侧以及如何减少窗口形式中两行图像之间的空间

C# 在表中列出了如何保持图片框的右侧以及如何减少窗口形式中两行图像之间的空间,c#,windows,winforms,tablelayoutpanel,C#,Windows,Winforms,Tablelayoutpanel,如何在c#中的TableLayoutPanel中获取右侧的图片框图像?目前,我得到两个图像除了,但我不需要。我只需要一个图像,他们在最右边,我需要删除两行之间的空间 for (int i = 0, r = 0; i < dt.Rows.Count; i++, r++) { PictureBox pb = new PictureBox(); pb.ImageLocation = ../imagesDT/answer

如何在c#中的
TableLayoutPanel
中获取右侧的图片框图像?目前,我得到两个图像除了,但我不需要。我只需要一个图像,他们在最右边,我需要删除两行之间的空间

         for (int i = 0, r = 0; i < dt.Rows.Count; i++, r++)
        {
           PictureBox pb = new PictureBox();
           pb.ImageLocation = ../imagesDT/answered.gif
           tableLayoutPanel1.Controls.Add(pb);
        }
for(int i=0,r=0;i

下面是我的附加图像,我得到的问题如上所述

您需要设置这些PictureBox应位于的列和行:

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 );
}
您可以通过设置边距来微调位置,例如:

pb.Margin = New Padding(50, 20, 0, 0);
要更改行的高度,可以使用设计器,也可以在每行的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);
}

你解决你的问题了吗?工作但不完全符合我的要求。在他们的图像将是两个标签之前,第二个标签文本转到另一行,当我将图像放置在右侧时,所有文本流都丢失了。@TaWMaybe您应该1)告诉我们表格的布局(列数),2)包括一个新的图像,它现在看起来是什么样子。Yopu必须以正确的顺序添加所有控件,并且不留下任何间隙,或者设置其正确的列和行位置。
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);
}