示例#1
0
 protected virtual GraphicsPath CreateBorderRectPath(RectangleF innerBorderRect)
 {
     return(GraphicsPathHelper.CreateRoundedRectPath(innerBorderRect, (float)CornerRadius, (float)CornerRadius));
 }
示例#2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);

            Graphics g = e.Graphics;


            #region 画客户区


            using (GraphicsPath path =
                       GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false))
            {
                g.SetClip(path);

                if (controlSchema.BackNormalStyle.Color2 != Color.Empty &&
                    controlSchema.BackNormalStyle.Color1 != controlSchema.BackNormalStyle.Color2)
                {
                    if (DisplayRectangle.Width > 0 && DisplayRectangle.Height > 0)
                    {
                        using (LinearGradientBrush br = new LinearGradientBrush(DisplayRectangle, controlSchema.BackNormalStyle.Color1, controlSchema.BackNormalStyle.Color2, controlSchema.BackNormalStyle.Mode))
                        {
                            g.FillPath(br, path);
                            //g.FillRectangle(br, DisplayRectangle);
                        }
                    }
                }
                else
                {
                    using (SolidBrush br = new SolidBrush(controlSchema.BackNormalStyle.Color1))
                    {
                        g.FillPath(br, path);
                        //g.FillRectangle(br, DisplayRectangle);
                    }
                }
            }



            #region 画背景图片
            if (BackgroundImage != null)
            {
                switch (BackgroundImageLayout)
                {
                case ImageLayout.None:
                    g.DrawImageUnscaled(BackgroundImage,
                                        DisplayRectangle.X,
                                        DisplayRectangle.Y,
                                        BackgroundImage.Width,
                                        BackgroundImage.Height);
                    break;

                case ImageLayout.Tile:
                    using (TextureBrush Txbrus = new TextureBrush(BackgroundImage))
                    {
                        Txbrus.WrapMode = WrapMode.Tile;

                        g.FillRectangle(Txbrus, new Rectangle(0, 0, DisplayRectangle.Width - 1, DisplayRectangle.Height - 1));
                    }
                    break;

                case ImageLayout.Center:

                    int xx = (DisplayRectangle.Width - BackgroundImage.Width) / 2;
                    int yy = (DisplayRectangle.Height - BackgroundImage.Height) / 2;
                    g.DrawImage(BackgroundImage, new Rectangle(xx, yy, BackgroundImage.Width, BackgroundImage.Height), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel);



                    break;

                case ImageLayout.Stretch:

                    g.DrawImage(BackgroundImage, new Rectangle(0, 0, DisplayRectangle.Width, DisplayRectangle.Height), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel);


                    break;

                case ImageLayout.Zoom:
                {
                    double tm = 0.0;
                    int    W  = BackgroundImage.Width;
                    int    H  = BackgroundImage.Height;
                    if (W > DisplayRectangle.Width)
                    {
                        tm = DisplayRectangle.Width / BackgroundImage.Width;
                        W  = (int)(W * tm);
                        H  = (int)(H * tm);
                    }
                    if (H > DisplayRectangle.Height)
                    {
                        tm = DisplayRectangle.Height / H;
                        W  = (int)(W * tm);
                        H  = (int)(H * tm);
                    }
                    using (Bitmap tmpBP = new Bitmap(W, H))
                    {
                        using (Graphics G2 = Graphics.FromImage(tmpBP))
                        {
                            G2.DrawImage(BackgroundImage, new Rectangle(0, 0, W, H), new Rectangle(0, 0, BackgroundImage.Width, BackgroundImage.Height), GraphicsUnit.Pixel);

                            int xxx = (DisplayRectangle.Width - W) / 2;
                            int yyy = (DisplayRectangle.Height - H) / 2;
                            g.DrawImage(tmpBP, new Rectangle(xxx, yyy, W, H), new Rectangle(0, 0, W, H), GraphicsUnit.Pixel);
                        }
                    }
                }
                break;
                }
            }

            #endregion


            #endregion

            #region 画标题
            OnPaintCaption(e);
            #endregion


            #region 画border
            using (SmoothingModeGraphics sgr = new SmoothingModeGraphics(g))
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;

                Rectangle r = ClientRectangle;
                //r.Width -= 1;
                //r.Height -= 1;
                using (GraphicsPath path =
                           GraphicsPathHelper.CreatePath(r, Radius, RoundStyle, true))
                {
                    using (Pen p = new Pen(controlSchema.BorderNormalStyle.Color1))
                    {
                        g.DrawPath(p, path);
                    }
                }

                if (controlSchema.BorderNormalStyle.Color2 != Color.Empty &&
                    controlSchema.BorderNormalStyle.Color2 != controlSchema.BorderNormalStyle.Color1)
                {
                    r.Inflate(-1, -1);
                    using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                               r, radius, roundStyle, true))
                    {
                        using (Pen pen = new Pen(controlSchema.BorderNormalStyle.Color2))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                }
            }
            #endregion
        }
示例#3
0
        /// <summary>
        /// 画bar条
        /// </summary>
        /// <param name="e"></param>
        protected virtual void RenderBar(PaintEventArgs e)
        {
            Color color1      = BarFaceSchema.BackNormalStyle.Color1;
            Color color2      = BarFaceSchema.BackNormalStyle.Color2;
            Color borderColor = BarFaceSchema.BorderNormalStyle.Color1;

            if (Enabled)
            {
                switch (ControlState)
                {
                case ControlState.Hover:
                case ControlState.Pressed:
                    color1 = BarFaceSchema.BackHoverStyle.Color1;
                    color2 = BarFaceSchema.BackHoverStyle.Color2;

                    borderColor = BarFaceSchema.BorderHoverStyle.Color1;
                    break;
                }
            }
            else
            {
                color1      = BarFaceSchema.BackDisabledStyle.Color1;
                color2      = BarFaceSchema.BackDisabledStyle.Color2;
                borderColor = BarFaceSchema.BorderDisabledStyle.Color1;
            }


            if (barRect.Width > 0 && barRect.Height > 0)
            {
                //draw bar
                using (
                    LinearGradientBrush lgbBar = new LinearGradientBrush(
                        barRect
                        , color1
                        , color2
                        , gradientOrientation)
                    )
                {
                    Rectangle r = new Rectangle();
                    //lgbBar.WrapMode = WrapMode.TileFlipXY;
                    if (Radius == 0)
                    {
                        e.Graphics.FillRectangle(lgbBar, barRect);
                        using (Pen p = new Pen(borderColor))
                        {
                            e.Graphics.DrawRectangle(p, barRect);
                        }
                    }
                    else
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(barRect, Radius, RoundStyle, false))
                        {
                            e.Graphics.FillPath(lgbBar, path);

                            using (Pen p = new Pen(borderColor))
                            {
                                e.Graphics.DrawPath(p, path);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        protected override void OnRenderImageMargin(
            ToolStripRenderEventArgs e)
        {
            if (e.ToolStrip is ToolStripDropDownMenu)
            {
                Rectangle rect = e.AffectedBounds;
                Graphics  g    = e.Graphics;
                rect.Width = OffsetMargin;
                if (e.ToolStrip.RightToLeft == RightToLeft.Yes)
                {
                    rect.X -= 2;
                }
                else
                {
                    rect.X += 2;
                }
                rect.Y         += 1;
                rect.Height    -= 2;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           rect,
                           ColorTable.BackColorHover,
                           Color.White,
                           90f))
                {
                    Blend blend = new Blend();
                    blend.Positions = new float[] { 0f, .2f, 1f };
                    blend.Factors   = new float[] { 0f, 0.1f, .9f };
                    brush.Blend     = blend;
                    rect.Y         += 1;
                    rect.Height    -= 2;
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(rect, 8, RoundStyle.All, false))
                    {
                        g.FillPath(brush, path);
                    }
                }

                g.TextRenderingHint = TextRenderingHint.AntiAlias;
                StringFormat sf   = new StringFormat(StringFormatFlags.NoWrap);
                Font         font = new Font(
                    e.ToolStrip.Font.FontFamily, 11, FontStyle.Bold);
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;

                g.TranslateTransform(rect.X, rect.Bottom);
                g.RotateTransform(270f);

                if (!string.IsNullOrEmpty(MenuLogoString))
                {
                    Rectangle newRect = new Rectangle(
                        rect.X, rect.Y, rect.Height, rect.Width);

                    using (Brush brush = new SolidBrush(ColorTable.ForeColor))
                    {
                        g.DrawString(
                            MenuLogoString,
                            font,
                            brush,
                            newRect,
                            sf);
                    }
                }

                g.ResetTransform();
                return;
            }

            base.OnRenderImageMargin(e);
        }
示例#5
0
        internal void RenderBackgroundInternal(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            RoundStyle 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] = baseColor; // GetColor(baseColor, 0, 35, 24, 9);
                colors[1] = baseColor; // GetColor(baseColor, 0, 13, 8, 3);
                colors[2] = baseColor;
                colors[3] = baseColor; // GetColor(baseColor, 0, 68, 69, 54);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.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 = GraphicsPathHelper.CreatePath(
                                   rectTop, roundWidth, RoundStyle.Top, false))
                        {
                            using (SolidBrush brushAlpha =
                                       new SolidBrush(Color.FromArgb(80, 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;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
                    }

                    if (drawBorder)
                    {
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            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
                {
                    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(80, 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;
                        }
                        ControlPaintEx.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);
                        }
                    }
                }
            }
        }
示例#6
0
 protected GraphicsPath CreateRectanglePath(RectangleF rect)
 {
     return(GraphicsPathHelper.CreateRoundedRectPath(rect, (float)RadiusX, (float)RadiusY));
 }
示例#7
0
        internal static void RenderBackgroundInternal3(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            RoundStyle style,
            int roundWidth,
            float basePosition,
            bool drawBorder,
            bool drawGlass,
            LinearGradientMode mode)
        {
            if (drawBorder)
            {
                rect.Width--;
                rect.Height--;
            }
            if (rect.Width < 1 || rect.Height < 1)
            {
                return;
            }
            using (LinearGradientBrush brush = new LinearGradientBrush(
                       rect, Color.Transparent, Color.Transparent, mode))
            {
                FillBrush(brush, baseColor, borderColor, basePosition, drawGlass);
                if (style != RoundStyle.None)
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                    {
                        g.FillPath(brush, path);
                    }

                    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;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 170, 0);

                        if (baseColor.A > 0)
                        {
                            Rectangle rectTop = rect;

                            if (mode == LinearGradientMode.Vertical)
                            {
                                rectTop.Height = (int)(rectTop.Height * basePosition);
                            }
                            else
                            {
                                rectTop.Width = (int)(rect.Width * basePosition);
                            }
                            using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath(
                                       rectTop, roundWidth, RoundStyle.Top, false))
                            {
                                using (SolidBrush brushAlpha =
                                           new SolidBrush(Color.FromArgb(128, 255, 255, 255)))
                                {
                                    g.FillPath(brushAlpha, pathTop);
                                }
                            }
                        }
                    }

                    if (drawBorder)
                    {
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
                        {
                            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
                {
                    g.FillRectangle(brush, rect);
                    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;
                        }
                        ControlPaintEx.DrawGlass(g, glassRect, 200, 0);

                        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 (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);
                        }
                    }
                }
            }
        }
示例#8
0
 public static void RenderBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle 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[]    colorArray = new Color[] { GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 0x23, 0x18, 9) };
         ColorBlend blend      = new ColorBlend();
         float[]    numArray   = new float[4];
         numArray[1]               = basePosition;
         numArray[2]               = basePosition + 0.05f;
         numArray[3]               = 1f;
         blend.Positions           = numArray;
         blend.Colors              = colorArray;
         brush.InterpolationColors = blend;
         if (style != RoundStyle.None)
         {
             using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 g.FillPath(brush, path);
             }
             if (drawGlass)
             {
                 if (baseColor.A > 80)
                 {
                     Rectangle rectangle = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectangle.Height = (int)(rectangle.Height * basePosition);
                     }
                     else
                     {
                         rectangle.Width = (int)(rect.Width * basePosition);
                     }
                     using (GraphicsPath path2 = GraphicsPathHelper.CreatePath(rectangle, roundWidth, RoundStyle.Top, false))
                     {
                         using (SolidBrush brush2 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                         {
                             g.FillPath(brush2, path2);
                         }
                     }
                 }
                 RectangleF glassRect = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     glassRect.Y      = rect.Y + (rect.Height * basePosition);
                     glassRect.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
                 }
                 else
                 {
                     glassRect.X     = rect.X + (rect.Width * basePosition);
                     glassRect.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
                 }
                 ControlPaintEx.DrawGlass(g, glassRect, 170, 0);
             }
             if (!drawBorder)
             {
                 return;
             }
             using (GraphicsPath path3 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 using (Pen pen = new Pen(borderColor))
                 {
                     g.DrawPath(pen, path3);
                 }
             }
             rect.Inflate(-1, -1);
             using (GraphicsPath path4 = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false))
             {
                 using (Pen pen2 = new Pen(innerBorderColor))
                 {
                     g.DrawPath(pen2, path4);
                 }
                 return;
             }
         }
         g.FillRectangle(brush, rect);
         if (drawGlass)
         {
             if (baseColor.A > 80)
             {
                 Rectangle rectangle2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rectangle2.Height = (int)(rectangle2.Height * basePosition);
                 }
                 else
                 {
                     rectangle2.Width = (int)(rect.Width * basePosition);
                 }
                 using (SolidBrush brush3 = new SolidBrush(Color.FromArgb(0x80, 0xff, 0xff, 0xff)))
                 {
                     g.FillRectangle(brush3, rectangle2);
                 }
             }
             RectangleF ef2 = rect;
             if (mode == LinearGradientMode.Vertical)
             {
                 ef2.Y      = rect.Y + (rect.Height * basePosition);
                 ef2.Height = (rect.Height - (rect.Height * basePosition)) * 2f;
             }
             else
             {
                 ef2.X     = rect.X + (rect.Width * basePosition);
                 ef2.Width = (rect.Width - (rect.Width * basePosition)) * 2f;
             }
             ControlPaintEx.DrawGlass(g, ef2, 200, 0);
         }
         if (drawBorder)
         {
             using (Pen pen3 = new Pen(borderColor))
             {
                 g.DrawRectangle(pen3, rect);
             }
             rect.Inflate(-1, -1);
             using (Pen pen4 = new Pen(innerBorderColor))
             {
                 g.DrawRectangle(pen4, rect);
             }
         }
     }
 }
示例#9
0
        private void RenderBackgroundInternal(Graphics g
                                              , Rectangle ClientRectangle
                                              , BrushParameter backStyle
                                              , BrushParameter bordStyle
                                              , Ants.Controls.RoundStyle RoundStyle
                                              , int Radius)
        {
            #region 画背景
            if (backStyle.Color2 == Color.Empty || backStyle.Color2 == backStyle.Color1)
            {
                using (SolidBrush brush = new SolidBrush(backStyle.Color1))
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true))
                    {
                        g.FillPath(brush, path);
                    }
                }
            }
            else
            {
                using (LinearGradientBrush brush = new LinearGradientBrush(
                           ClientRectangle, backStyle.Color1, backStyle.Color2, backStyle.Mode))
                {
                    using (GraphicsPath path =
                               GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true))
                    {
                        g.FillPath(brush, path);
                    }
                }
            }
            #endregion


            #region 画边框
            using (GraphicsPath path =
                       GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true))
            {
                using (Pen pen = new Pen(bordStyle.Color1))
                {
                    g.DrawPath(pen, path);
                }
            }
            if (bordStyle.Color2 != Color.Empty)
            {
                ClientRectangle.Inflate(-1, -1);
                Rectangle r = ClientRectangle;
                r.X      += 1;
                r.Y      += 1;
                r.Width  -= 2;
                r.Height -= 2;

                using (GraphicsPath path =
                           //GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, false))
                           GraphicsPathHelper.CreatePath(ClientRectangle, Radius, RoundStyle, true))
                {
                    using (Pen pen = new Pen(bordStyle.Color2))
                    {
                        g.DrawPath(pen, path);
                    }
                }
            }

            #endregion
        }
示例#10
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            base.OnPaintBackground(e);



            Graphics  g = e.Graphics;
            Rectangle imageRect;
            Rectangle textRect;

            CalculateRect(out imageRect, out textRect);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Color textColor = ControlFaceSchema.TextNormalStyle.Color1;

            if (!ImageMode)//文本模式
            {
                if (Enabled)
                {
                    if (Checked)
                    {
                        switch (ControlState)
                        {
                        case ControlState.Hover:
                            RenderBackgroundInternal(g
                                                     , ClientRectangle
                                                     , ControlFaceSchema.BackHoverStyle
                                                     , ControlFaceSchema.BorderHoverStyle
                                                     , RoundStyle
                                                     , Radius);
                            textColor = ControlFaceSchema.TextHoverStyle.Color1;
                            break;

                        default:
                            RenderBackgroundInternal(g
                                                     , ClientRectangle
                                                     , ControlFaceSchema.BackCheckedStyle
                                                     , ControlFaceSchema.BorderCheckedStyle
                                                     , RoundStyle
                                                     , Radius);
                            textColor = ControlFaceSchema.TextCheckedStyle.Color1;
                            break;
                        }
                    }
                    else
                    {
                        switch (ControlState)
                        {
                        case ControlState.Hover:
                            RenderBackgroundInternal(g
                                                     , ClientRectangle
                                                     , ControlFaceSchema.BackHoverStyle
                                                     , ControlFaceSchema.BorderHoverStyle
                                                     , RoundStyle
                                                     , Radius);
                            textColor = ControlFaceSchema.TextHoverStyle.Color1;
                            break;

                        case ControlState.Pressed:
                            RenderBackgroundInternal(g
                                                     , ClientRectangle
                                                     , ControlFaceSchema.BackCheckedStyle
                                                     , ControlFaceSchema.BorderCheckedStyle
                                                     , RoundStyle
                                                     , Radius);
                            textColor = ControlFaceSchema.TextCheckedStyle.Color1;
                            break;

                        default:
                            RenderBackgroundInternal(g
                                                     , ClientRectangle
                                                     , ControlFaceSchema.BackNormalStyle
                                                     , ControlFaceSchema.BorderNormalStyle
                                                     , RoundStyle
                                                     , Radius);
                            textColor = ControlFaceSchema.TextNormalStyle.Color1;
                            break;
                        }
                    }
                }
                else
                {
                    RenderBackgroundInternal(g
                                             , ClientRectangle
                                             , ControlFaceSchema.BackDisabledStyle
                                             , ControlFaceSchema.BorderDisabledStyle
                                             , RoundStyle
                                             , Radius);
                    textColor = ControlFaceSchema.TextDisabledStyle.Color1;
                }



                if (Image != null)
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    g.DrawImage(
                        Image,
                        imageRect,
                        0,
                        0,
                        Image.Width,
                        Image.Height,
                        GraphicsUnit.Pixel);
                }
                //画玻璃效果
                if (GlassEnable && Enabled)
                {
                    Rectangle r = ClientRectangle;
                    r.Height = r.Height / 2;
                    if (r.Height > 0 && r.Width > 0)
                    {
                        using (GraphicsPath path =
                                   GraphicsPathHelper.CreatePathHalf(ClientRectangle, Radius, RoundStyle, true))
                        {
                            //255:表示完全不透明,color1是上面。
                            using (LinearGradientBrush br = new LinearGradientBrush(r, Color.FromArgb(255, Color.White), Color.FromArgb(70, Color.White), 90))
                            {
                                g.FillPath(br, path);
                            }
                        }
                    }
                }
                //TextRenderer.DrawText(
                //    g,
                //    Text,
                //    Font,
                //    textRect,
                //    textColor,
                //    GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes));

                using (StringFormat sf = new StringFormat())
                {
                    sf.Alignment     = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    sf.Trimming      = StringTrimming.EllipsisCharacter;

                    using (SolidBrush br = new SolidBrush(textColor))
                    {
                        g.DrawString(Text, Font, br, textRect, sf);
                    }
                }
            }
            else//图片模式,直接根据状态贴图即可
            {
                Image img = ImageTable.ImageNormal;
                if (Checked)
                {
                    img = ImageTable.ImageChecked;
                }
                else
                {
                    if (Enabled)
                    {
                        switch (ControlState)
                        {
                        case Ants.Controls.ControlState.Hover:
                            img = ImageTable.ImageHover;
                            break;

                        case Ants.Controls.ControlState.Normal:
                            img = ImageTable.ImageNormal;
                            break;

                        case Ants.Controls.ControlState.Pressed:
                            img = ImageTable.ImageChecked;
                            break;
                        }
                    }
                    else
                    {
                        img = ImageTable.ImageDisalbed;
                    }
                }
                if (img != null)
                {
                    this.Text            = string.Empty;
                    this.BackgroundImage = img;
                    base.OnPaint(e);


                    //this.Width = img.Width;
                    //this.Height = img.Height;
                    //g.DrawImage(
                    //    img,
                    //    e.ClipRectangle,
                    //    0,
                    //    0,
                    //    img.Width,
                    //    img.Height,
                    //    GraphicsUnit.Pixel);
                }

                if (this.DesignMode)
                {
                    using (Pen pen = new Pen(Color.Gray))
                    {
                        Rectangle r = ClientRectangle;
                        r.Height -= 1;
                        r.Width  -= 1;
                        g.DrawRectangle(pen, r);
                    }
                }
            }
        }
示例#11
0
        protected override void DoPerformLayout(RenderContext context)
        {
            base.DoPerformLayout(context);

            // Setup brushes
            if (Fill != null || ((Stroke != null && StrokeThickness > 0)))
            {
                using (GraphicsPath path = CalculateTransformedPath(ParsePath(), _innerRect))
                {
                    if (Fill != null && !_fillDisabled)
                    {
                        using (GraphicsPathIterator gpi = new GraphicsPathIterator(path))
                        {
                            PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][];
                            using (GraphicsPath subPath = new GraphicsPath())
                            {
                                for (int i = 0; i < subPathVerts.Length; i++)
                                {
                                    bool isClosed;
                                    gpi.NextSubpath(subPath, out isClosed);
                                    PointF[] pathPoints = subPath.PathPoints;
                                    TriangulateHelper.Triangulate(pathPoints, 1, out subPathVerts[i]);
                                    if (subPathVerts[i] == null)
                                    {
                                        ServiceRegistration.Get <ILogger>().Warn("Failed to triangulate Path \"{0}\"!", Name);
                                    }
                                }
                            }
                            PositionColoredTextured[] verts;
                            GraphicsPathHelper.Flatten(subPathVerts, out verts);
                            if (verts != null)
                            {
                                Fill.SetupBrush(this, ref verts, context.ZOrder, true);
                                PrimitiveBuffer.SetPrimitiveBuffer(ref _fillContext, ref verts, PrimitiveType.TriangleList);
                            }
                        }
                    }
                    else
                    {
                        PrimitiveBuffer.DisposePrimitiveBuffer(ref _fillContext);
                    }

                    if (Stroke != null && StrokeThickness > 0)
                    {
                        using (GraphicsPathIterator gpi = new GraphicsPathIterator(path))
                        {
                            PositionColoredTextured[][] subPathVerts = new PositionColoredTextured[gpi.SubpathCount][];
                            using (GraphicsPath subPath = new GraphicsPath())
                            {
                                for (int i = 0; i < subPathVerts.Length; i++)
                                {
                                    bool isClosed;
                                    gpi.NextSubpath(subPath, out isClosed);
                                    PointF[] pathPoints = subPath.PathPoints;
                                    TriangulateHelper.TriangulateStroke_TriangleList(pathPoints, (float)StrokeThickness, isClosed, 1, StrokeLineJoin,
                                                                                     out subPathVerts[i]);
                                }
                            }
                            PositionColoredTextured[] verts;
                            GraphicsPathHelper.Flatten(subPathVerts, out verts);
                            if (verts != null)
                            {
                                Stroke.SetupBrush(this, ref verts, context.ZOrder, true);
                                PrimitiveBuffer.SetPrimitiveBuffer(ref _strokeContext, ref verts, PrimitiveType.TriangleList);
                            }
                        }
                    }
                    else
                    {
                        PrimitiveBuffer.DisposePrimitiveBuffer(ref _strokeContext);
                    }
                }
            }
        }
示例#12
0
文件: NCPanel.cs 项目: icprog/MaTuo
        protected virtual void WmNcPaint(ref Message m)
        {
            IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd);

            if (hDC == IntPtr.Zero)
            {
                return;
            }

            try
            {
                Rectangle bounds = new Rectangle(Point.Empty, base.Size);
                Rectangle client = base.ClientRectangle;
                client.X = _borderWidth;
                client.Y = _borderWidth;

                using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height))
                {
                    Win32.NativeMethods.ExcludeClipRect(
                        bufferedDC.Hdc,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    DrawTransparentBackground(
                        bufferedDC.Hdc,
                        bounds,
                        base.Location);

                    using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc))
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            g.SetClip(path);
                        }
                        g.ExcludeClip(client);

                        if (base.BackgroundImage != null)
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                g,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }
                        else if (base.BackColor != Color.Transparent)
                        {
                            using (Brush brush = new SolidBrush(base.BackColor))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                        }

                        g.ResetClip();

                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            using (SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g))
                            {
                                g.DrawPath(Pens.Black, path);
                            }
                        }
                    }

                    Win32.NativeMethods.ExcludeClipRect(
                        hDC,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    Win32.NativeMethods.BitBlt(
                        hDC,
                        bounds.X,
                        bounds.Y,
                        bounds.Width,
                        bounds.Height,
                        bufferedDC.Hdc,
                        0,
                        0,
                        TernaryRasterOperations.SRCCOPY);
                }
            }
            catch
            {
            }
            finally
            {
                Win32.NativeMethods.ReleaseDC(m.HWnd, hDC);
            }
        }