Пример #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
        /// <summary>
        /// Draws the <see cref="BackgroundImage"/> property onto <see cref="MobileUserControl"/>
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (BackgroundImage == null)
            {
                return;
            }

            var image = BackgroundImage;

            if (AutoScaleBackgroundImage && Dpi.IsHiDpi)
            {
                image = ImageManipulator.Stretch(BackgroundImage, Dpi.ScaleSize(BackgroundImage.Size));
            }

            var gfx = GraphicsEx.FromGraphics(e.Graphics);

            gfx.DrawImage(image, ClientSize, BackgroundDrawMode);
        }