示例#1
0
 internal static void RenderBackgroundInternal(
     Graphics G,
     Rectangle Rect,
     Color BaseColor,
     Color BorderColor,
     Color InnerBorderColor,
     ToolTipRoundStyle RStyle,
     int RoundWidth,
     bool DrawBorder,
     bool DrawGlass,
     LinearGradientMode Mode)
 {
     RenderBackgroundInternal(
         G,
         Rect,
         BaseColor,
         BorderColor,
         InnerBorderColor,
         RStyle,
         8,
         0.45f,
         DrawBorder,
         DrawGlass,
         Mode);
 }
 public static void CreateRegion(
     Control Ctrl,
     Rectangle BoundsRect,
     int Radius,
     ToolTipRoundStyle RStyle)
 {
     using (GraphicsPath path = ToolTipGraphicsPathHelper.CreatePath(BoundsRect, Radius, RStyle, true))
     {
         Region region = new Region(path);
         path.Widen(Pens.White);
         region.Union(path);
         if (Ctrl.Region != null)
         {
             Ctrl.Region.Dispose();
         }
         Ctrl.Region = region;
     }
 }
示例#3
0
        internal static void RenderBackgroundInternal(
            Graphics G,
            Rectangle Rect,
            Color BaseColor,
            Color BorderColor,
            Color InnerBorderColor,
            ToolTipRoundStyle Style,
            int RoundWidth,
            float BasePosition,
            bool DrawBorder,
            bool DrawGlass,
            LinearGradientMode Mode)
        {
            if (DrawBorder)
            {
                Rect.Width--;
                Rect.Height--;
            }
            using (LinearGradientBrush brush = new LinearGradientBrush(Rect, Color.Transparent, Color.Transparent, Mode))
            {
                Color[] colors = new Color[4];
                colors[0] = GetColor(BaseColor, 0, 35, 24, 9);
                colors[1] = GetColor(BaseColor, 0, 13, 8, 3);
                colors[2] = BaseColor;
                colors[3] = GetColor(BaseColor, 0, 35, 24, 9);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, BasePosition, BasePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;

                if (Style != ToolTipRoundStyle.None)
                {
                    using (GraphicsPath path = ToolTipGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false))
                    {
                        G.FillPath(brush, path);
                    }
                    if (BaseColor.A > 80)
                    {
                        Rectangle rectTop = Rect;

                        if (Mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * BasePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(Rect.Width * BasePosition);
                        }
                        using (GraphicsPath pathTop = ToolTipGraphicsPathHelper.CreatePath(rectTop, RoundWidth, ToolTipRoundStyle.Top, false))
                        {
                            using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                            {
                                G.FillPath(brushAlpha, pathTop);
                            }
                        }
                    }
                    if (DrawGlass)
                    {
                        RectangleF glassRect = Rect;

                        if (Mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = Rect.Y + Rect.Height * BasePosition;
                            glassRect.Height = (Rect.Height - Rect.Height * BasePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = Rect.X + Rect.Width * BasePosition;
                            glassRect.Width = (Rect.Width - Rect.Width * BasePosition) * 2;
                        }
                        ToolTipControlPaintEx.DrawGlass(G, glassRect, 170, 0);
                    }

                    if (DrawBorder)
                    {
                        using (GraphicsPath path = ToolTipGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false))
                        {
                            using (Pen pen = new Pen(BorderColor))
                            {
                                G.DrawPath(pen, path);
                            }
                        }
                        Rect.Inflate(-1, -1);

                        using (GraphicsPath path = ToolTipGraphicsPathHelper.CreatePath(Rect, RoundWidth, Style, false))
                        {
                            using (Pen pen = new Pen(InnerBorderColor))
                            {
                                G.DrawPath(pen, path);
                            }
                        }
                    }
                }
                else
                {
                    G.FillRectangle(brush, Rect);

                    if (BaseColor.A > 80)
                    {
                        Rectangle rectTop = Rect;

                        if (Mode == LinearGradientMode.Vertical)
                        {
                            rectTop.Height = (int)(rectTop.Height * BasePosition);
                        }
                        else
                        {
                            rectTop.Width = (int)(Rect.Width * BasePosition);
                        }
                        using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                        {
                            G.FillRectangle(brushAlpha, rectTop);
                        }
                    }

                    if (DrawGlass)
                    {
                        RectangleF glassRect = Rect;

                        if (Mode == LinearGradientMode.Vertical)
                        {
                            glassRect.Y      = Rect.Y + Rect.Height * BasePosition;
                            glassRect.Height = (Rect.Height - Rect.Height * BasePosition) * 2;
                        }
                        else
                        {
                            glassRect.X     = Rect.X + Rect.Width * BasePosition;
                            glassRect.Width = (Rect.Width - Rect.Width * BasePosition) * 2;
                        }
                        ToolTipControlPaintEx.DrawGlass(G, glassRect, 200, 0);
                    }
                    if (DrawBorder)
                    {
                        using (Pen pen = new Pen(BorderColor))
                        {
                            G.DrawRectangle(pen, Rect);
                        }
                        Rect.Inflate(-1, -1);

                        using (Pen pen = new Pen(InnerBorderColor))
                        {
                            G.DrawRectangle(pen, Rect);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 建立帶有圓角的樣式的路徑。
        /// </summary>
        /// <param name="Rect">用來建立路徑的矩形。</param>
        /// <param name="Radius">圓角的大小。</param>
        /// <param name="Style">圓角的樣式。</param>
        /// <param name="Correction">是否把矩形長寬减 1,以便畫出邊框。</param>
        /// <returns>建立的路徑。</returns>
        public static GraphicsPath CreatePath(
            Rectangle Rect, int Radius, ToolTipRoundStyle Style, bool Correction)
        {
            GraphicsPath path             = new GraphicsPath();
            int          radiusCorrection = Correction ? 1 : 0;

            switch (Style)
            {
            case ToolTipRoundStyle.None:
                path.AddRectangle(Rect);
                break;

            case ToolTipRoundStyle.All:
                path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90);
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Y,
                    Radius,
                    Radius,
                    270,
                    90);
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius, 0, 90);
                path.AddArc(
                    Rect.X,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    90,
                    90);
                break;

            case ToolTipRoundStyle.Left:
                path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90);
                path.AddLine(
                    Rect.Right - radiusCorrection, Rect.Y,
                    Rect.Right - radiusCorrection, Rect.Bottom - radiusCorrection);
                path.AddArc(
                    Rect.X,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    90,
                    90);
                break;

            case ToolTipRoundStyle.Right:
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Y,
                    Radius,
                    Radius,
                    270,
                    90);
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    0,
                    90);
                path.AddLine(Rect.X, Rect.Bottom - radiusCorrection, Rect.X, Rect.Y);
                break;

            case ToolTipRoundStyle.Top:
                path.AddArc(Rect.X, Rect.Y, Radius, Radius, 180, 90);
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Y,
                    Radius,
                    Radius,
                    270,
                    90);
                path.AddLine(
                    Rect.Right - radiusCorrection, Rect.Bottom - radiusCorrection,
                    Rect.X, Rect.Bottom - radiusCorrection);
                break;

            case ToolTipRoundStyle.Bottom:
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    0,
                    90);
                path.AddArc(
                    Rect.X,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    90,
                    90);
                path.AddLine(Rect.X, Rect.Y, Rect.Right - radiusCorrection, Rect.Y);
                break;

            case ToolTipRoundStyle.BottomLeft:
                path.AddArc(
                    Rect.X,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    90,
                    90);
                path.AddLine(Rect.X, Rect.Y, Rect.Right - radiusCorrection, Rect.Y);
                path.AddLine(
                    Rect.Right - radiusCorrection,
                    Rect.Y,
                    Rect.Right - radiusCorrection,
                    Rect.Bottom - radiusCorrection);
                break;

            case ToolTipRoundStyle.BottomRight:
                path.AddArc(
                    Rect.Right - Radius - radiusCorrection,
                    Rect.Bottom - Radius - radiusCorrection,
                    Radius,
                    Radius,
                    0,
                    90);
                path.AddLine(Rect.X, Rect.Bottom - radiusCorrection, Rect.X, Rect.Y);
                path.AddLine(Rect.X, Rect.Y, Rect.Right - radiusCorrection, Rect.Y);
                break;
            }
            path.CloseFigure();

            return(path);
        }