Ejemplo n.º 1
0
        /// <summary></summary>
        /// <param name="control"></param>
        public static GradientColor GetGradientColor(Control control)
        {
            GradientColor gradientColor = new GradientColor();

            if (IsMdiClient(control))
            {
                control = control.Parent;
            }

            if (control is IGradientColorProperty)
            {
                gradientColor = ((IGradientColorProperty)control).GradientColor;
            }

            return(gradientColor);
        }
Ejemplo n.º 2
0
        /// <summary></summary>
        /// <param name="control"></param>
        /// <param name="gradientColor"></param>
        public static void SetGradientColor(Control control, GradientColor gradientColor)
        {
            if (IsMdiClient(control))
            {
                control = control.Parent;
            }

            if (control is IGradientColorProperty)
            {
                IGradientColorProperty gradientColorProperty = (IGradientColorProperty)control;
                if ((gradientColorProperty.GradientColor != gradientColor))
                {
                    gradientColorProperty.GradientColor = gradientColor;

                    control.Refresh();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary> paint control backgound and image</summary>
        /// <param name="control"></param>
        /// <param name="graphics"></param>
        /// <param name="useImageSize" - do the image will be display on all the control (for button image)></param>
        /// <param name="DisplayRect" - the display rect of the color></param>
        public static void PaintBackgoundColorAndImage(Control control, Graphics graphics, bool useImageSize, Rectangle DisplayRect)
        {
            Image         backgroundImage = null;
            GradientColor gradientColor   = ControlUtils.GetGradientColor(control);
            GradientStyle gradientStyle   = ControlUtils.GetGradientStyle(control);

            ControlRenderer.FillRectAccordingToGradientStyle(graphics, DisplayRect, control.BackColor,
                                                             control.ForeColor, ControlStyle.NoBorder,
                                                             false, gradientColor, gradientStyle);

#if !PocketPC
            backgroundImage = control.BackgroundImage;
#else
            if (control is ButtonBase)
            {
                ButtonBase button = (ButtonBase)control;
                backgroundImage = button.BackgroundImage;
            }
            else if (control is MgPanel)
            {
                MgPanel panel = (MgPanel)control;
                backgroundImage = panel.BackGroundImage;
            }
#endif

            if (backgroundImage != null)
            {
                Rectangle rectImage;
                if (useImageSize)
                {
                    rectImage = new Rectangle(DisplayRect.X, DisplayRect.Y, backgroundImage.Width, backgroundImage.Height);
                }
                else
                {
                    rectImage = control.ClientRectangle;
                }

                DrawImage(graphics, rectImage, backgroundImage, 0, 0);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// paint the BackGround Gradient
        /// </summary>
        /// <param name="g"></param>
        /// <param name="gradientRect"></param>
        /// <param name="bgColor"></param>
        /// <param name="fgColor"></param>
        /// <param name="style"></param>
        /// <param name="TextBoxBorder"></param>
        /// <param name="GradientFromColor"></param>
        /// <param name="GradientToColor"></param>
        /// <param name="GradientStyle"></param>
        /// <returns></returns>
        public static void PaintBackGroundGradient(Graphics g, Rectangle gradientRect, Color bgColor, Color fgColor,
                                                   ControlStyle style, bool textBoxBorder, GradientColor gradientColor,
                                                   GradientStyle gradientStyle, bool paintRoundedRectangle, ulong cornerRadius)
        {
            if (gradientRect.Width <= 0 || gradientRect.Height <= 0)
            {
                return;
            }

#if PocketPC
            PaintBackGroundGradientMobile(g, gradientRect, bgColor, fgColor, style,
                                          textBoxBorder, gradientColor, gradientStyle);
#else
            //QCR #915016, enable has effect in foreground only
            //GradientFromColor = (enabled ? GradientFromColor : getGrayScaleColor(GradientFromColor));
            // GradientToColor = (enabled ? GradientToColor : getGrayScaleColor(GradientToColor));
            if (gradientStyle == GradientStyle.None)
            {
                Debug.Assert(false);
            }
            // Create a horizontal linear gradient with four stops.
            Blend blend = new Blend(3);
            blend.Factors   = new float[] { 0.0f, 0.75f, 1.0f };
            blend.Positions = new float[] { 0.0f, 0.5f, 1.0f };
            switch (gradientStyle)
            {
            case GradientStyle.HorizontalSymmetric:
            case GradientStyle.VerticalSymmetric:
            case GradientStyle.DiagonalLeftSymmetric:
            case GradientStyle.DiagonalRightSymmetric:
                blend.Factors[1] = 1.0f;
                blend.Factors[2] = 0.0f;
                break;
            }
            switch (gradientStyle)
            {
            case GradientStyle.HorizontalSymmetric:
            case GradientStyle.VerticalSymmetric:
            case GradientStyle.DiagonalLeftSymmetric:
            case GradientStyle.DiagonalRightSymmetric:
            case GradientStyle.Horizontal:
            case GradientStyle.Vertical:
            case GradientStyle.DiagonalLeft:
            case GradientStyle.DiagonalRight:
                LinearGradientBrush myHorizontalGradient1 = new LinearGradientBrush(gradientRect, gradientColor.From, gradientColor.To, GetLinearGradientMode(gradientStyle));
                myHorizontalGradient1.Blend           = blend;
                myHorizontalGradient1.GammaCorrection = true;
                // Use the brush to paint the rectangle.
                if (paintRoundedRectangle)
                {
                    GraphicsExtension.FillRoundedRectangle(g, myHorizontalGradient1, gradientRect.Left, gradientRect.Top, gradientRect.Width, gradientRect.Height, (int)cornerRadius);
                }
                else
                {
                    g.FillRectangle(myHorizontalGradient1, gradientRect);
                }
                break;

            case GradientStyle.VerticalWide:
            case GradientStyle.HorizontalWide:
            {
                // Create a path that consists of a single rectangle.
                GraphicsPath path = new GraphicsPath();
                /// Add the rectangle
                path.AddRectangle(gradientRect);
                // Use the path to construct a brush.
                PathGradientBrush pthGrBrush = new PathGradientBrush(path);
                // Set the center point to a location that is not the centroid of the path.
                if (gradientStyle == GradientStyle.HorizontalWide)
                {
                    pthGrBrush.FocusScales = new PointF(0.92f, 0.5f);
                }
                else if (gradientStyle == GradientStyle.VerticalWide)
                {
                    pthGrBrush.FocusScales = new PointF(0.5f, 0.92f);
                }
                // Set the color at the center point to blue.
                pthGrBrush.CenterColor = gradientColor.To;
                // Set the color along the entire boundary of the path to aqua.
                Color[] colors = new Color[] { gradientColor.From };
                pthGrBrush.SurroundColors = colors;
                //? pthGrBrush.GammaCorrection = true;
                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94101&wa=wsignin1.0
                if (paintRoundedRectangle)
                {
                    GraphicsExtension.FillRoundedRectangle(g, pthGrBrush, gradientRect.Left, gradientRect.Top, gradientRect.Width, gradientRect.Height, (int)cornerRadius);
                }
                else
                {
                    g.FillRectangle(pthGrBrush, gradientRect);
                }
            }
            break;

            case GradientStyle.CornerBottomRight:
            case GradientStyle.CornerBottomLeft:
            case GradientStyle.CornerTopLeft:
            case GradientStyle.CornerTopRight:
            case GradientStyle.Center:
            {
                // Create a path that consists of a single rectangle.
                GraphicsPath path = new GraphicsPath();
                /// Add the rectangle
                path.AddRectangle(gradientRect);
                // Use the path to construct a brush.
                PathGradientBrush pthGrBrush = new PathGradientBrush(path);
                // Set the center point to a location that is not the centroid of the path.
                SetCorner(pthGrBrush, gradientStyle, gradientRect);
                // Set the color at the center point to blue.
                pthGrBrush.CenterColor = gradientColor.From;
                // Set the color along the entire boundary of the path to aqua.
                Color[] colors = new Color[] { gradientColor.To };
                pthGrBrush.SurroundColors = colors;
                //? pthGrBrush.GammaCorrection = true;
                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94101&wa=wsignin1.0
                if (paintRoundedRectangle)
                {
                    GraphicsExtension.FillRoundedRectangle(g, pthGrBrush, gradientRect.Left, gradientRect.Top, gradientRect.Width, gradientRect.Height, (int)cornerRadius);
                }
                else
                {
                    g.FillRectangle(pthGrBrush, gradientRect);
                }
            }
            break;

            case GradientStyle.None:
                //assert(false);
                break;

            default:
                break;
            }
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="g"></param>
        /// <param name="gradientRect"></param>
        /// <param name="bgColor"></param>
        /// <param name="fgColor"></param>
        /// <param name="style"></param>
        /// <param name="TextBoxBorder"></param>
        /// <param name="GradientFromColor"></param>
        /// <param name="GradientToColor"></param>
        /// <param name="GradientStyle"></param>
        /// <returns></returns>
        internal static void PaintBackGroundGradientMobile(Graphics g, Rectangle gradientRect, Color bgColor, Color fgColor,
                                                           ControlStyle style, bool textBoxBorder, GradientColor gradientColor,
                                                           GradientStyle gradientStyle)
        {
            //QCR #915016, enable has effect in foreground only
            // GradientFromColor = (enabled ? GradientFromColor : getGrayScaleColor(GradientFromColor));
            // GradientToColor = (enabled ? GradientToColor : getGrayScaleColor(GradientToColor));
            if (gradientStyle == GradientStyle.None)
            {
                Debug.Assert(false);
            }

            switch (gradientStyle)
            {
            case GradientStyle.Horizontal:
            case GradientStyle.HorizontalSymmetric:
            case GradientStyle.HorizontalWide:
                GradientFill.Fill(g, gradientRect, gradientColor.From, gradientColor.To,
                                  GradientFill.FillDirection.Vertical);
                break;

            case GradientStyle.Vertical:
            case GradientStyle.VerticalSymmetric:
            case GradientStyle.VerticalWide:
                GradientFill.Fill(g, gradientRect, gradientColor.From, gradientColor.To,
                                  GradientFill.FillDirection.Horizontal);
                break;

            case GradientStyle.CornerBottomRight:
            case GradientStyle.CornerBottomLeft:
            case GradientStyle.CornerTopLeft:
            case GradientStyle.CornerTopRight:
            case GradientStyle.Center:
                PaintBackgroundAndBorder(g, gradientRect, bgColor, fgColor, style, textBoxBorder, true);
                break;

            case GradientStyle.None://1
                //assert(false);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
        //TODO: Kaushal. When the rendering code will be moved from MgUtils to MgControls,
        //the scope of many methods in this class should be changed to private.

        /// <summary>
        /// paint background of control
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="bgColor"></param>
        /// <param name="fgColor"></param>
        /// <param name="style"></param>
        /// <param name="textBoxBorder"></param>
        /// <param name="gradientColor"></param>
        /// <param name="gradientStyle"></param>
        /// <param name="borderType"></param>
        /// <returns></returns>
        public static Rectangle FillRectAccordingToGradientStyle(Graphics g, Rectangle rect, Color bgColor, Color fgColor,
                                                                 ControlStyle style, bool textBoxBorder, GradientColor gradientColor,
                                                                 GradientStyle gradientStyle, BorderType borderType = BorderType.Thin)
        {
            if (gradientStyle == GradientStyle.None)
            {
                PaintBackGround(g, rect, bgColor, true);
            }
            else
            {
                PaintBackGroundGradient(g, rect, bgColor, fgColor, style, textBoxBorder,
                                        gradientColor, gradientStyle, false, 0);
            }

            BorderRenderer.PaintBorder(g, rect, fgColor, style, textBoxBorder, borderType);

            return(rect);
        }