0

I am trying to show images in a row..For this I am trying to add picture boxes dynamically. Image location is stored in databses. my code is as

int iCtr = 0;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            PictureBox picture = new PictureBox
            {
                Name = "pictureBox"+i,
                Size = new Size(316, 320),
                Location = new Point(1, iCtr * 1100 + 1),
                Visible = true
            };
           // string fname = dt.Rows[2]["FileName"].ToString();
            picture.ImageLocation = dt.Rows[i]["FileName"].ToString();
            //@"..\Images\80knhk00003.jpg";
            pnlDisplayImage.Controls.Add(picture);
            iCtr++;
        }

where dt is datable.

with this I can see only last image but not all images. Even last image is very small and complete image is not shown.(i.e. I can view only one corner of actual image).

How can I give size to image so that it can be viewed completely? And how can I display images in row?

Please help Thanks

4

2 回答 2

3

你可以试试这样的东西吗?要获得缩放,请参阅PictureBoxSizeMode

List<PictureBox> pictureBoxList = new List<PictureBox>();

for (int i = 0; i < dt.Rows.Count; i++)
{
    PictureBox picture = new PictureBox
    {
        Name = "pictureBox" + i,
        Size = new Size(316, 320),
        Location = new Point(i * 316, 1),
        BorderStyle = BorderStyle.FixedSingle,
        SizeMode = PictureBoxSizeMode.Zoom
    };
    picture.ImageLocation = dt.Rows[i]["FileName"].ToString();
    pictureBoxList.Add(picture);
}

foreach (PictureBox p in pictureBoxList)
{
    pnlDisplayImage.Controls.Add(p);
}
于 2012-06-30T14:50:53.670 回答
-1

而不是 Image 属性,将 BackGroundImage 属性设置为您的图片位置,然后将 BackGroundImageLayout 设置为值“Stretch”,然后您将看到完整的图像。

于 2012-06-30T14:28:36.523 回答