坐标为C#的多张图片

时间:2013-07-24 14:54:52

标签: c# image picturebox

嗨我是c#编程的菜鸟,我试图把很多照片放到15x20 但我想把它们放在直接坐标示例中:

picture1:Y = 10 X = 35

picture2 Y = 250 X = 126

picture3 Y = 73 X = 97

就像其中的30个。

pictureBox1.Image = Image.FromFile(@“C:\ blue.png”);

任何提示? 感谢

1 个答案:

答案 0 :(得分:0)

如果您想动态布局图片,可能会像以下代码一样。

private void buttonLayout_Click(object sender, EventArgs e)
    {
        int x=0;
        int y=0;          
        for (int index = 0; index < 6;index++ )
        {
            string path = @"C:\Pictures\" + index.ToString() + ".png";
            if (!File.Exists(path))
            {
                continue;
            }
            Image image=Image.FromFile(path);
            PictureBox pictureBox = new PictureBox();
            pictureBox.Image = image;
            pictureBox.BorderStyle = BorderStyle.FixedSingle;
            pictureBox.Left = x;
            pictureBox.Top = y;
            pictureBox.Width = image.Width;
            pictureBox.Height = image.Height;
            pictureBox.SizeMode = PictureBoxSizeMode.Normal;
            panelPictures.Controls.Add(pictureBox);
            x += pictureBox.Image.Width;               
        }            
    }

如果布局更多行,请检查x和y是否在范围内。