Ejemplo n.º 1
0
        protected override void DrawItemText(TabItemPaintEventArgs e, Rectangle rect)
        {
            //base.DrawItemText(e, rect);

            var   taskBar   = e.GetBar <TaskBar>();
            Color foreColor = taskBar.ItemForeColor;

            switch (e.Status)
            {
            case UIControlStatus.Selected:
            case UIControlStatus.Focused:
                if (taskBar.IsActive)
                {
                    foreColor = taskBar.SelectedItemForeColor;
                }
                else
                {
                    foreColor = taskBar.InactiveSelectedItemForeColor;
                }
                break;

            case UIControlStatus.Hover:
                foreColor = taskBar.HoverItemForeColor;
                break;
            }

            if (!foreColor.IsEmpty)
            {
                StringFormat sf = PaintHelper.SFCenter;
                sf.FormatFlags |= StringFormatFlags.NoWrap;
                e.Graphics.DrawString(e.Item.Text, e.Font, new SolidBrush(foreColor), rect, sf);
            }
        }
Ejemplo n.º 2
0
        protected override void DrawCloseButton(TabItemPaintEventArgs e, Rectangle rect)
        {
            //Skin.Instance.DrawTaskBarItemCloseButton(new SkinPaintEventArgs(this, e), rect, tis, Alignment, item == SelectedItem);
            Image image = Properties.Resources.close_button; // Images.close_button;

            Rectangle rectS = new Rectangle(0, 0, image.Width / 4, image.Height);

            if (!e.Selected)
            {
                rectS.X = rectS.Width * 3;
            }

            switch (e.CloseButtonStatus)
            {
            case UIControlStatus.Hover:
                rectS.X = rectS.Width * 1;
                break;

            case UIControlStatus.Selected:
                rectS.X = rectS.Width * 2;
                break;

            case UIControlStatus.Disabled:
                rectS.X = rectS.Width * 3;
                break;
            }

            PaintHelper.DrawImageInRange(e.Graphics, image, rect, rectS);
        }
Ejemplo n.º 3
0
        protected override void DrawCloseButton(TabItemPaintEventArgs e, Rectangle rect)
        {
            Image         image = Properties.Resources.taskbar_close_button;
            UIStatusImage img   = UIStatusImage.FromVertical(image,
                                                             new UIControlStatus[] {
                UIControlStatus.Normal,
                UIControlStatus.Hover,
                UIControlStatus.Selected,
                UIControlStatus.InactivedHover,
                UIControlStatus.Inactived,
                UIControlStatus.Disabled
            });

            var bs = e.CloseButtonStatus;

            if (!e.Selected)
            {
                if (bs == UIControlStatus.Hover || bs == UIControlStatus.Selected)
                {
                    bs = UIControlStatus.InactivedHover;
                }
                else
                {
                    bs = UIControlStatus.Inactived;
                }
            }

            img.Draw(e.Graphics, bs, rect);
        }
Ejemplo n.º 4
0
        protected override void DrawItemBackground(TabItemPaintEventArgs e)
        {
            //base.DrawItemBackground(e);

            TaskBar taskBar   = e.GetBar <TaskBar>();
            Color   backColor = e.Bar.ItemBackColor;

            switch (e.Status)
            {
            case UIControlStatus.Selected:
            case UIControlStatus.Focused:
                if (taskBar.IsActive)
                {
                    backColor = taskBar.SelectedItemBackColor;
                }
                else
                {
                    backColor = taskBar.InactiveSelectedItemBackColor;
                }
                break;

            case UIControlStatus.Hover:
                backColor = taskBar.HoverItemBackColor;
                break;
            }

            if (!backColor.IsEmpty)
            {
                GraphicsPath path = PaintHelper.GetRoundRectangle(e.Bounds, taskBar.TabRounded, taskBar.TabRounded, 0, 0);
                //if (e.Status == UIControlStatus.Hover)
                //{
                //    LinearGradientBrush backBrush = new LinearGradientBrush(e.Bounds, backColor, backColor, 90.0f);
                //    ColorBlend cb = new ColorBlend(3);
                //    cb.Colors = new Color[] { PaintHelper.GetLightColor(backColor), backColor, backColor };
                //    cb.Positions = new float[] { 0.0f, 0.5f, 1.0f };
                //    backBrush.InterpolationColors = cb;
                //    e.Graphics.FillPath(backBrush, path);
                //}
                //else
                //{
                SolidBrush backBrush = new SolidBrush(backColor);
                e.Graphics.FillPath(backBrush, path);
                //}

                //
                if ((e.Status == UIControlStatus.Normal || e.Status == UIControlStatus.Hover) &&
                    e.Bounds.Height > 10)
                {
                    Rectangle rectShadow = e.Bounds;
                    rectShadow.Y      = rectShadow.Bottom - 6;
                    rectShadow.Height = 5;
                    var brush = new LinearGradientBrush(rectShadow, Color.Transparent,
                                                        PaintHelper.AdjustColorSLess(PaintHelper.GetDarkColor(backColor), 20), 90.0f);
                    rectShadow.Y++;//规避一个Gdi+错误, 会导致第一行有一个很深的线
                    //e.Graphics.FillRectangle(Brushes.Red, rectShadow);
                    e.Graphics.FillRectangle(brush, rectShadow);
                }
            }
        }
Ejemplo n.º 5
0
        protected virtual void DrawItemBorder(TabItemPaintEventArgs e, Rectangle rect, Color color)
        {
            rect.Width--;
            rect.Height--;
            if (rect.Width <= 0 || rect.Height <= 0)
            {
                return;
            }

            Point[] pts = null;
            switch (Bar.Alignment)
            {
            case TabAlignment.Left:
                pts = new Point[] {
                    new Point(rect.Right, rect.Top),
                    new Point(rect.Left, rect.Top),
                    new Point(rect.Left, rect.Bottom),
                    new Point(rect.Right, rect.Bottom)
                };
                break;

            case TabAlignment.Bottom:
                pts = new Point[] {
                    new Point(rect.X, rect.Top),
                    new Point(rect.X, rect.Bottom),
                    new Point(rect.Right, rect.Bottom),
                    new Point(rect.Right, rect.Top)
                };
                break;

            case TabAlignment.Right:
                pts = new Point[] {
                    new Point(rect.Left, rect.Top),
                    new Point(rect.Right, rect.Top),
                    new Point(rect.Right, rect.Bottom),
                    new Point(rect.Left, rect.Bottom)
                };
                break;

            case TabAlignment.Top:
            default:
                pts = new Point[] {
                    new Point(rect.X, rect.Bottom),
                    new Point(rect.X, rect.Y),
                    new Point(rect.Right, rect.Y),
                    new Point(rect.Right, rect.Bottom)
                };
                break;
            }

            Pen pen = new Pen(color);
            var pom = e.Graphics.PixelOffsetMode;

            e.Graphics.PixelOffsetMode = PixelOffsetMode.Default;
            e.Graphics.DrawLines(pen, pts);
            e.Graphics.PixelOffsetMode = pom;
            //e.Graphics.DrawPath(new Pen(Bar.BaseLineColor), path);
        }
Ejemplo n.º 6
0
        protected virtual void DrawItemText(TabItemPaintEventArgs e, Rectangle rect)
        {
            Color foreColor = e.Bar.ItemForeColor;

            switch (e.Status)
            {
            case UIControlStatus.Selected:
            case UIControlStatus.Focused:
                foreColor = e.Bar.SelectedItemForeColor;
                break;

            case UIControlStatus.Hover:
                foreColor = e.Bar.HoverItemForeColor;
                break;
            }

            if (!foreColor.IsEmpty)
            {
                StringFormat sf = e.HalfDisplay ? PaintHelper.SFLeft : PaintHelper.SFCenter;
                sf.FormatFlags |= StringFormatFlags.NoWrap;
                sf.Trimming     = StringTrimming.None;

                if (e.IsHorizontal)
                {
                    rect.X     += e.Padding.Left;
                    rect.Width -= e.Padding.Horizontal;
                }
                else
                {
                    rect.Y      += e.Padding.Top;
                    rect.Height -= e.Padding.Vertical;
                }

                e.Graphics.DrawString(e.Item.Text, e.Font, new SolidBrush(foreColor), rect, sf);
            }
        }
Ejemplo n.º 7
0
 protected abstract void DrawCloseButton(TabItemPaintEventArgs e, Rectangle rect);
Ejemplo n.º 8
0
 public abstract void DrawItem(TabItemPaintEventArgs e);
Ejemplo n.º 9
0
        public override void DrawItem(TabItemPaintEventArgs e)
        {
            Rectangle rect = e.Bounds;

            if (rect.Width <= 0 || rect.Height <= 0)
            {
                return;
            }

            // draw background
            DrawItemBackground(e);

            rect = e.ContentRectangle;
            // draw icon
            if (e.Item.Icon != null)
            {
                Rectangle rect_icon;
                if (e.IsHorizontal)
                {
                    if (string.IsNullOrEmpty(e.Item.Text) && !e.Item.CanClose)
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                    else
                    {
                        rect_icon = new Rectangle(rect.Left, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(e.Item.Text) && !e.Item.CanClose)
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top + (rect.Height - e.IconSize.Height) / 2, e.IconSize.Width, e.IconSize.Height);
                    }
                    else
                    {
                        rect_icon = new Rectangle(rect.Left + (rect.Width - e.IconSize.Width) / 2, rect.Top, e.IconSize.Width, e.IconSize.Height);
                    }
                }

                PaintHelper.DrawImageInRange(e.Graphics, e.Item.Icon, rect_icon);
                if (e.IsHorizontal)
                {
                    rect.X     += rect_icon.Width;
                    rect.Width -= rect_icon.Width;
                }
                else
                {
                    rect.Y      += rect_icon.Height;
                    rect.Height -= rect_icon.Height;
                }
            }

            if (e.Item.CanClose)
            {
                //System.Diagnostics.Debug.WriteLine(string.Format("> {0}, {1}", HoverHitResult.Item, HoverHitResult.InCloseButton));

                Rectangle rect_close_btn = e.Item.GetCloseButtonRect();
                DrawCloseButton(e, rect_close_btn);
                if (e.IsHorizontal)
                {
                    rect.Width -= e.Bar.CloseButtonSize.Width;
                }
                else
                {
                    rect.Height -= e.Bar.CloseButtonSize.Height;
                }
            }

            if (!string.IsNullOrEmpty(e.Item.Text))
            {
                Rectangle     rect_text = rect;
                GraphicsState gs        = null;
                if (!e.IsHorizontal)
                {
                    gs = e.Graphics.Save();
                    e.Graphics.RotateTransform(90);
                    rect_text = new Rectangle(rect.Y, -rect.X - rect.Width, rect.Height, rect.Width);
                    //e.Graphics.DrawRectangle(Pens.Blue, rect_text);
                }

                DrawItemText(e, rect_text);

                if (!e.IsHorizontal)
                {
                    e.Graphics.Restore(gs);
                }
            }
        }
Ejemplo n.º 10
0
        protected virtual void DrawItemBackground(TabItemPaintEventArgs e)
        {
            var   rect        = e.Bounds;
            Color borderColor = Color.Empty;

            if (e.Selected)
            {
                // 把BaseLineSize加回去
                switch (e.Bar.Alignment)
                {
                case TabAlignment.Left:
                    rect.Width += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Top:
                    rect.Height += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Right:
                    rect.X     -= e.Bar.BaseLineSize;
                    rect.Width += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Bottom:
                    rect.Y      -= e.Bar.BaseLineSize;
                    rect.Height += e.Bar.BaseLineSize;
                    break;
                }

                Color backColor = e.Item.BackColor ?? e.Bar.SelectedItemBackColor;
                if (!backColor.IsEmpty)
                {
                    //LinearGradientBrush backBrush = new LinearGradientBrush(e.Bounds, PaintHelper.GetLightColor(backColor), backColor, 90.0f);
                    var backBrush = new SolidBrush(backColor);
                    e.Graphics.FillRectangle(backBrush, rect);
                }

                borderColor = e.Bar.BaseLineColor;
            }
            else
            {
                Color backColor = e.Item.BackColor ?? e.Bar.ItemBackColor;
                switch (e.Status)
                {
                case UIControlStatus.Hover:
                    backColor = e.Bar.HoverItemBackColor;
                    break;
                }

                if (!backColor.IsEmpty)
                {
                    var backBrush = new SolidBrush(backColor);
                    e.Graphics.FillRectangle(backBrush, e.Item.Bounds);

                    borderColor = PaintHelper.AdjustColorS(PaintHelper.GetDarkColor(backColor, 0.15), 10, 20);
                }
            }

            if (!borderColor.IsEmpty)
            {
                DrawItemBorder(e, rect, borderColor);
            }
        }
Ejemplo n.º 11
0
        protected override void DrawItemBackground(TabItemPaintEventArgs e)
        {
            Rectangle rect = e.Bounds;

            //
            Color backColor;

            if (e.Selected)
            {
                backColor = e.Bar.SelectedItemBackColor;

                // 把BaseLineSize加回去
                switch (e.Bar.Alignment)
                {
                case TabAlignment.Left:
                    rect.Width += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Top:
                    rect.Height += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Right:
                    rect.X     -= e.Bar.BaseLineSize;
                    rect.Width += e.Bar.BaseLineSize;
                    break;

                case TabAlignment.Bottom:
                    rect.Y      -= e.Bar.BaseLineSize;
                    rect.Height += e.Bar.BaseLineSize;
                    break;
                }
            }
            else if (e.Hover)
            {
                backColor = e.Bar.HoverItemBackColor;
            }
            else
            {
                backColor = e.Bar.ItemBackColor;
            }
            e.Graphics.FillRectangle(new SolidBrush(backColor), rect);

            //
            if (e.Item.BackColor.HasValue)
            {
                Rectangle rectC;
                switch (e.Bar.Alignment)
                {
                case TabAlignment.Left:
                    rectC = new Rectangle(rect.X, rect.Y, Math.Min(3, rect.Width / 3), rect.Height);
                    break;

                case TabAlignment.Right:
                    rectC  = new Rectangle(rect.X, rect.Y, Math.Min(3, rect.Width / 3), rect.Height);
                    rect.X = rect.Right - rectC.Width - 1;
                    break;

                case TabAlignment.Bottom:
                    rectC   = new Rectangle(rect.X, rect.Y, rect.Width, Math.Min(3, rect.Height / 3));
                    rectC.Y = rect.Bottom - rectC.Height - 1;
                    break;

                case TabAlignment.Top:
                default:
                    rectC = new Rectangle(rect.X, rect.Y, rect.Width, Math.Min(3, rect.Height / 3));
                    break;
                }

                if (rectC.Height > 0)
                {
                    e.Graphics.FillRectangle(new SolidBrush(e.Item.BackColor.Value), rectC);
                }
            }

            if (!e.Bar.BaseLineColor.IsEmpty)
            {
                DrawItemBorder(e, rect, e.Bar.BaseLineColor);
                //Point[] points = new Point[] {
                //    new Point(rect.X, rect.Bottom),
                //    new Point(rect.X, rect.Top),
                //    new Point(rect.Right-1, rect.Top),
                //    new Point(rect.Right-1, rect.Bottom),
                //};

                //PixelOffsetMode pom = e.Graphics.PixelOffsetMode;
                //e.Graphics.PixelOffsetMode = PixelOffsetMode.Default;
                //e.Graphics.DrawLines(new Pen(e.Bar.BaseLineColor), points);
                //e.Graphics.PixelOffsetMode = pom;
                ////e.Graphics.DrawPath(new Pen(Bar.BaseLineColor), path);
            }
        }