Пример #1
0
        /// <summary>
        /// Draws the background of the parent control giving a transparent effect
        /// </summary>
        /// <param name="graphics">Drawing surface</param>
        /// <param name="form">Parent Container that implements <see cref="IControlBackground"/></param>
        /// <param name="bounds">Bounds of the Control</param>
        /// <param name="parent">Instance of the Parent Container</param>
        public void DrawBackground(Graphics graphics, IControlBackground form, Rectangle bounds, Control parent)
        {
            if (form.BackgroundImage == null)
            {
                return;
            }

            var g = GraphicsEx.FromGraphics(graphics);

            switch (form.BackgroundDrawMode)
            {
            case ImageDrawMode.Normal:
                g.DrawImage(form.BackgroundImage, 0, 0, bounds);
                break;

            case ImageDrawMode.Center:
                Point location = GraphicsEx.GetCenter(form.BackgroundImage.Size, parent.ClientSize);
                g.DrawImage(form.BackgroundImage,
                            location.X,
                            location.Y,
                            new Rectangle(bounds.X,
                                          bounds.Y,
                                          form.BackgroundImage.Width,
                                          form.BackgroundImage.Height));
                break;

            case ImageDrawMode.Stretch:
                using (Image image = ImageManipulator.Stretch(form.BackgroundImage, parent.ClientSize))
                    g.DrawImage(image, 0, 0, bounds);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        private void DrawCentered(GraphicsEx graphics)
        {
            Point           location   = GraphicsEx.GetCenter(ClientSize, Image.Size);
            ImageAttributes attributes = GetImageAttributes(Image);

            graphics.DrawImage(Image,
                               new Rectangle(location.X, location.Y, Image.Width, Image.Height),
                               new Rectangle(0, 0, Image.Width, Image.Height),
                               attributes);
        }