1

画像の幅は 200px で、pictureBox の幅は 400px です。

画像の repeat-x を表示するには、pictureBox のどのプロパティを設定すればよいですか?

4

1 に答える 1

2

I don't think there is any property which makes the image display x times repeatedly horizontally. But a little custom code can help, here is my code:

public static class PictureBoxExtension
{
    public static void SetImage(this PictureBox pic, Image image, int repeatX)
    {
        Bitmap bm = new Bitmap(image.Width * repeatX, image.Height);
        Graphics gp = Graphics.FromImage(bm);
        for (int x = 0; x <= bm.Width - image.Width; x += image.Width)
        {
            gp.DrawImage(image, new Point(x, 0));
        }
        pic.Image = bm;
    }
}

//Now you can use the extension method SetImage to make the PictureBox display the image x-repeatedly 
myPictureBox.SetImage(myImage, 3);//repeat 3 images horizontally.

You can customize the code to make it repeat vertically or look like a check board.

Hope it helps!

于 2013-06-07T04:42:09.573 に答える