Ejemplo n.º 1
0
 private GraphicsPath GetPath(Rectangle rect, int raduio)
 {
     return(DrawHelper.CreateRoundPath2(rect, raduio));
 }
Ejemplo n.º 2
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--;
     }
     if (rect.Width == 0 || rect.Height == 0)
     {
         return;
     }
     using (var brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode))
     {
         Color[] colorArray =
         {
             GetColor(baseColor, 0, 0x23, 0x18, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor,
             GetColor(baseColor, 0, 0x23, 0x18, 9)
         };
         var blend    = new ColorBlend();
         var 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))
             using (var path = DrawHelper.CreateRoundPath(rect, roundWidth, style, false))
             {
                 g.FillPath(brush, path);
             }
             if (drawGlass)
             {
                 if (baseColor.A > 80)
                 {
                     var rectangle = rect;
                     if (mode == LinearGradientMode.Vertical)
                     {
                         rectangle.Height = (int)(rectangle.Height * basePosition);
                     }
                     else
                     {
                         rectangle.Width = (int)(rect.Width * basePosition);
                     }
                     using (var path2 = DrawHelper.CreateRoundPath(rectangle, roundWidth, RoundStyle.Top, false))
                     //
                     {
                         using (var 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 (var path3 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen = new Pen(borderColor))
                 {
                     g.DrawPath(pen, path3);
                 }
             }
             rect.Inflate(-1, -1);
             using (var path4 = DrawHelper.CreateRoundPath(rect, roundWidth, style, false)) //
             {
                 using (var pen2 = new Pen(innerBorderColor))
                 {
                     g.DrawPath(pen2, path4);
                 }
                 return;
             }
         }
         g.FillRectangle(brush, rect);
         if (drawGlass)
         {
             if (baseColor.A > 80)
             {
                 var rectangle2 = rect;
                 if (mode == LinearGradientMode.Vertical)
                 {
                     rectangle2.Height = (int)(rectangle2.Height * basePosition);
                 }
                 else
                 {
                     rectangle2.Width = (int)(rect.Width * basePosition);
                 }
                 using (var 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 (var pen3 = new Pen(borderColor))
             {
                 g.DrawRectangle(pen3, rect);
             }
             rect.Inflate(-1, -1);
             using (var pen4 = new Pen(innerBorderColor))
             {
                 g.DrawRectangle(pen4, rect);
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     关闭Tab之前触发事件
        /// </summary>
        /// <summary>
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (!Visible)
            {
                return;
            }
            //画选点击选项卡,
            if (TabCount > 0)
            {
                var g = e.Graphics;
                Share.GraphicSetup(g);
                //  g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                // g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                // alpha = Alpha.Normal;
                var sb = new SolidBrush(Share.BackColor);

                var pen = new Pen(Share.BorderColor);
                //   g.FillPath(sb, GetPath(ClientRectangle, 5)); //画整体边框
                //   g.DrawPath(pen, GetPath(ClientRectangle, 5)); //画整体背景
                var tabRect       = Rectangle.Empty;
                var selecttabRect = Rectangle.Empty;
                // Point cursorPoint = this.PointToClient(MousePosition);
                TabPage      page       = null;
                TabPage      selectPage = null;
                GraphicsPath gp         = null;
                GraphicsPath selectgp   = null;

                for (var i = 0; i < TabCount; i++)
                {
                    page       = TabPages[i];
                    tabRect    = GetTabRect(i);
                    tabRect.X += 2;
                    tabRect.Y += 2;
                    gp         = DrawHelper.GetGoogleTabPath(tabRect, 8);
                    if (SelectedIndex != i)
                    {
                        //  alpha = Alpha.MoveOrUp;
                        page.ForeColor = Color.CornflowerBlue;
                        //   sb = new SolidBrush(color);
                        //   pen = new Pen(color);
                        sb.Color = Share.DisabelBackColor;

                        g.FillPath(sb, gp);  //画边框
                        g.DrawPath(pen, gp); //画背景
                        gp.Dispose();
                        //  sb.Dispose();
                        //渲染选项卡文字
                        tabRect.X     += 10; //让文字往右偏移10个像素.因为谷歌的tab 是个梯形的
                        tabRect.Width -= 20;
                        TextRenderer.DrawText(g, page.Text, page.Font, tabRect,
                                              page.ForeColor,
                                              TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis |
                                              TextFormatFlags.HorizontalCenter);
                    }
                    else
                    {
                        selectPage    = page;
                        selectgp      = gp;
                        selecttabRect = tabRect;
                    }
                    if (i == TabCount - 1)
                    {
                        selectPage.ForeColor = Color.Orange;
                        // alpha = Alpha.a200;
                        //  sb = new SolidBrush(color);
                        //  pen = new Pen(color);
                        sb.Color = Share.BackColor;
                        g.FillPath(sb, selectgp);  //画背景
                        g.DrawPath(pen, selectgp); //画边框
                        selectgp.Dispose();
                        // sb.Dispose();
                        //画叉叉 ,叉叉是在最上层的, 所以要最后画
                        Bitmap clsBitmap;
                        if (closeState == MouseState.press)
                        {
                            clsBitmap = Properties.Resources.icon_tbclose_press;
                        }
                        else if (closeState == MouseState.move)
                        {
                            clsBitmap = Properties.Resources.icon_tbclose_hover;
                        }
                        else
                        {
                            clsBitmap = Properties.Resources.icon_tbclose_normal;
                        }
                        g.DrawImage(clsBitmap, GetCloseRect(selecttabRect));
                        clsBitmap.Dispose();
                        //渲染选项卡文字
                        selecttabRect.X     += 10; //让文字往右偏移10个像素.因为谷歌的tab 是个梯形的
                        selecttabRect.Width -= 20;
                        TextRenderer.DrawText(g, selectPage.Text, selectPage.Font, selecttabRect,
                                              selectPage.ForeColor,
                                              TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis |
                                              TextFormatFlags.HorizontalCenter);

                        var rect = new Rectangle(GetTabRect(0).X + 2,
                                                 GetTabRect(0).Bottom + 2,
                                                 TabPages[0].DisplayRectangle.Width + 6,
                                                 TabPages[0].DisplayRectangle.Height + 6);
                        var path = GetPath(rect, 5);
                        pen.Color = Share.BorderColor;
                        g.DrawPath(pen, path); //画页面边框
                        path.Dispose();
                    }
                }
                sb.Dispose();
                pen.Dispose();
            }
        }