-2

Hi im a noob in c# programing, Im trying to put a lot pictures 15x20 but i want to put them in direfent coordinates example:

picture1: Y=10 X =35

picture2 Y= 250 X =126

picture3 Y= 73 X = 97

is like 30 of them.

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

any hint? Thanks

4

1 回答 1

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 是否在范围内。

于 2013-07-25T01:10:02.723 回答