Beispiel #1
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();
            }
        }