Exemple #1
0
 /// <summary>
 /// 画边框与背景
 /// </summary>
 /// <param name="g"></param>
 /// <param name="rect"></param>
 /// <param name="style"></param>
 /// <param name="roundWidth"></param>
 internal void RenderBackGroundInternal(Graphics g, Rectangle rect, RoundInRectStyle style, int roundWidth)
 {
     //       if (ControlState != ControlState.Normal || AlwaysShowBorder)
     //       {
     //      rect.Width--;
     //       rect.Height--;
 }
Exemple #2
0
        /// <summary>
        /// 画边框与背景
        /// </summary>
        /// <param name="g"></param>
        /// <param name="rect"></param>
        /// <param name="style"></param>
        /// <param name="roundWidth"></param>
        internal void RenderBackGroundInternal(Graphics g, Rectangle rect, RoundInRectStyle style, int roundWidth)
        {
            //       if (ControlState != ControlState.Normal || AlwaysShowBorder)
            //       {
            rect.Width--;
            rect.Height--;
            if (style != RoundInRectStyle.None)
            {
                using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                {
                    if (ControlState == MouseState.Normal)
                    {
                        using (SolidBrush brush = new SolidBrush(_baseColor))
                        {
                            if (!ShowSpliteButton)
                            {
                                g.FillPath(brush, path);
                            }
                        }
                    }
                    //if (ControlState != ControlState.Normal)
                    else
                    {
                        using (LinearGradientBrush brush = (ControlState == MouseState.Pressed) ? new LinearGradientBrush(rect, _baseColorEnd, _baseColor, LinearGradientMode.ForwardDiagonal) : new LinearGradientBrush(rect, _baseColor, _baseColorEnd, LinearGradientMode.Vertical))
                        {
                            if (!ShowSpliteButton)
                            {
                                g.FillPath(brush, path);
                            }
                            else
                            {
                                if (CurrentMousePosition == ButtonMousePosition.Button)
                                {
                                    using (GraphicsPath buttonpath = GraphicsPathHelper.CreatePath(ButtonRect, roundWidth, RoundInRectStyle.Left, true))
                                    {
                                        g.FillPath(brush, buttonpath);
                                    }
                                }
                                else
                                {
                                    using (GraphicsPath splitepath = GraphicsPathHelper.CreatePath(SpliteButtonRect, roundWidth, RoundInRectStyle.Right, true))
                                    {
                                        g.FillPath(brush, splitepath);
                                    }
                                }
                            }
                        }
                    }
                    //using (Pen pen = new Pen(_borderColor))
                    //{
                    //    g.DrawPath(pen, path);
                    //}
                }
                //rect.Inflate(-1, -1);
                //using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                //{
                //    using (Pen pen = new Pen(InnerBorderColor))
                //    {
                //        g.DrawPath(pen, path);
                //    }
                //}
            }
            else
            {
                if (ControlState != MouseState.Normal)
                {
                    if (ControlState == MouseState.Normal)
                    {
                        using (SolidBrush brush = new SolidBrush(_baseColor))
                        {
                            if (!ShowSpliteButton)
                            {
                                g.FillRectangle(brush, rect);
                            }
                        }
                    }
                    //if (ControlState != ControlState.Normal)
                    else
                    {
                        using (LinearGradientBrush brush = (ControlState == MouseState.Pressed) ? new LinearGradientBrush(rect, _baseColorEnd, _baseColor, LinearGradientMode.ForwardDiagonal) : new LinearGradientBrush(rect, _baseColor, _baseColorEnd, LinearGradientMode.Vertical))

                            if (!ShowSpliteButton)
                            {
                                g.FillRectangle(brush, rect);
                            }
                            else
                            {
                                if (CurrentMousePosition == ButtonMousePosition.Button)
                                {
                                    g.FillRectangle(brush, ButtonRect);
                                }
                                else
                                {
                                    g.FillRectangle(brush, SpliteButtonRect);
                                }
                            }
                    }
                }
                //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, RoundInRectStyle style, bool correction)
        {
            GraphicsPath path             = new GraphicsPath();
            int          radiusCorrection = correction ? 1 : 0;

            switch (style)
            {
            case RoundInRectStyle.None:
                path.AddRectangle(rect);
                break;

            case RoundInRectStyle.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 RoundInRectStyle.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 RoundInRectStyle.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 RoundInRectStyle.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 RoundInRectStyle.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 RoundInRectStyle.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 RoundInRectStyle.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);
        }