This project is read-only.

how to set a tile background on a ImageBox?

Jan 3, 2014 at 3:09 PM
i tried to set a small pic as ImageBox background and set it like a tile, but i found that is no posible after looking at your code:
public Rectangle SourceRect
                {
                        get { return sourceRect; }
                        set
                        {
                                if (value != null && image != null)
                                {
                                        int l = value.Left;
                                        int t = value.Top;
                                        int w = value.Width;
                                        int h = value.Height;

                                        if (l < 0) l = 0;
                                        if (t < 0) t = 0;
                                        if (w > image.Width) w = image.Width;
                                        if (h > image.Height) h = image.Height;
                                        if (l + w > image.Width) w = (image.Width - l);
                                        if (t + h > image.Height) h = (image.Height - t);

                                        sourceRect = new Rectangle(l, t, w, h);
                                }
                                else if (image != null)
                                {
                                        sourceRect = new Rectangle(0, 0, image.Width, image.Height);
                                }
                                else
                                {
                                        sourceRect = Rectangle.Empty;
                                }
                                Invalidate();
                        }
                }
coz the sourcerect is always limited to image size. Is there any way to use an image as a background tile on a ImageBox? thanks.