Ejemplo n.º 1
0
        protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
        {
            Rectangle      rc  = e.ImageRectangle;
            TabStripButton btn = e.Item as TabStripButton;

            if (btn != null)
            {
                int delta = ((Mirrored) ? -1 : 1) * ((btn.Checked) ? 1 : selOffset);
                if (e.ToolStrip.Orientation == Orientation.Horizontal)
                {
                    rc.Offset((Mirrored) ? 2 : 1, delta + ((Mirrored) ? 1 : 0));
                }
                else
                {
                    rc.Offset(delta + 2, 0);
                }
            }
            ToolStripItemImageRenderEventArgs x =
                new ToolStripItemImageRenderEventArgs(e.Graphics, e.Item, e.Image, rc);

            if (currentRenderer != null)
            {
                currentRenderer.DrawItemImage(x);
            }
            else
            {
                base.OnRenderItemImage(x);
            }
        }
Ejemplo n.º 2
0
 protected override void OnItemAdded(ToolStripItemEventArgs e)
 {
     base.OnItemAdded(e);
     if (e.Item is TabStripButton)
     {
         SelectedTab = (TabStripButton)e.Item;
     }
 }
Ejemplo n.º 3
0
 protected void OnTabSelected(TabStripButton tab)
 {
     this.Invalidate();
     if (SelectedTabChanged != null)
     {
         SelectedTabChanged(this, new SelectedTabChangedEventArgs(tab));
     }
 }
Ejemplo n.º 4
0
        protected override void OnItemClicked(ToolStripItemClickedEventArgs e)
        {
            TabStripButton clickedBtn = e.ClickedItem as TabStripButton;

            if (clickedBtn != null)
            {
                this.SuspendLayout();
                mySelTab = clickedBtn;
                this.ResumeLayout();
                OnTabSelected(clickedBtn);
            }
            base.OnItemClicked(e);
        }
Ejemplo n.º 5
0
        protected void OnInsertPageClicked(object sender, EventArgs e)
        {
            ISite site = base.Site;

            if (site != null && site.DesignMode)
            {
                IContainer container = site.Container;
                if (container != null)
                {
                    TabStripButton btn = new TabStripButton();
                    container.Add(btn);
                    btn.Text = btn.Name;
                }
            }
        }
Ejemplo n.º 6
0
        void TabPages_Inserted(object sender, EventArgs <StripTabPage> e)
        {
            e.Item.StripTabControl = this;

            ///添加JeeluTabPage到当前控件
            e.Item.Dock         = DockStyle.Fill;
            e.Item.Visible      = false;
            e.Item.TextChanged += new EventHandler(Item_TextChanged);
            _mainPanel.Controls.Add(e.Item);

            ///添加TabPage对应的按钮
            var strip = new TabStripButton(e.Item.Text);

            strip.Tag    = e.Item;
            strip.Click += new EventHandler(strip_Click);
            this.LeftStrip.Items.Add(strip);
            e.Item.TabStripButton = strip;
        }
Ejemplo n.º 7
0
        protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
        {
            Rectangle      rc  = e.TextRectangle;
            TabStripButton btn = e.Item as TabStripButton;
            Color          c   = e.TextColor;
            Font           f   = e.TextFont;

            if (btn != null)
            {
                int delta = ((Mirrored) ? -1 : 1) * ((btn.Checked) ? 1 : selOffset);
                if (e.ToolStrip.Orientation == Orientation.Horizontal)
                {
                    rc.Offset((Mirrored) ? 2 : 1, delta + ((Mirrored) ? 1 : -1));
                }
                else
                {
                    rc.Offset(delta + 2, 0);
                }
                if (btn.Selected)
                {
                    c = btn.HotTextColor;
                }
                else if (btn.Checked)
                {
                    c = btn.SelectedTextColor;
                }
                if (btn.Checked)
                {
                    f = btn.SelectedFont;
                }
            }
            ToolStripItemTextRenderEventArgs x =
                new ToolStripItemTextRenderEventArgs(e.Graphics, e.Item, e.Text, rc, c, f, e.TextFormat);

            x.TextDirection = e.TextDirection;
            if (currentRenderer != null)
            {
                currentRenderer.DrawItemText(x);
            }
            else
            {
                base.OnRenderItemText(x);
            }
        }
Ejemplo n.º 8
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics       g    = e.Graphics;
            TabStrip       tabs = e.ToolStrip as TabStrip;
            TabStripButton tab  = e.Item as TabStripButton;

            if (tabs == null || tab == null)
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                }
                else
                {
                    base.OnRenderButtonBackground(e);
                }
                return;
            }

            bool      selected = tab.Checked;
            bool      hovered  = tab.Selected;
            int       top      = 0;
            int       left     = 0;
            int       width    = tab.Bounds.Width - 1;
            int       height   = tab.Bounds.Height - 1;
            Rectangle drawBorder;


            if (UseVS)
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    drawBorder = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (!selected)
                    {
                        left   = selOffset;
                        width -= (selOffset - 1);
                    }
                    else
                    {
                        left = 1;
                    }
                    drawBorder = new Rectangle(0, 0, height, width);
                }
                using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height))
                {
                    VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal;
                    if (selected)
                    {
                        el = VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (hovered)
                    {
                        el = VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!tab.Enabled)
                    {
                        el = VisualStyleElement.Tab.TabItem.Disabled;
                    }

                    if (!selected || hovered)
                    {
                        drawBorder.Width++;
                    }
                    else
                    {
                        drawBorder.Height++;
                    }

                    using (Graphics gr = Graphics.FromImage(b))
                    {
                        VisualStyleRenderer rndr = new VisualStyleRenderer(el);
                        rndr.DrawBackground(gr, drawBorder);

                        if (tabs.Orientation == Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipXY);
                            }
                            else
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }
                        }
                        if (Mirrored)
                        {
                            left = tab.Bounds.Width - b.Width - left;
                            top  = tab.Bounds.Height - b.Height - top;
                        }
                        g.DrawImage(b, left, top);
                    }
                }
            }
            else
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    if (Mirrored)
                    {
                        left = 1;
                        top  = 0;
                    }
                    else
                    {
                        top++;
                    }
                    width--;
                }
                else
                {
                    if (!selected)
                    {
                        left = selOffset;
                        width--;
                    }
                    else
                    {
                        left = 1;
                    }
                    if (Mirrored)
                    {
                        left = 0;
                        top  = 1;
                    }
                }
                height--;
                drawBorder = new Rectangle(left, top, width, height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    if (Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top);
                    }
                    else if (!Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom);
                    }
                    else if (Mirrored && tabs.Orientation == Orientation.Vertical)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom);
                    }
                    else
                    {
                        gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom);
                    }

                    if (selected || hovered)
                    {
                        Color fill = (hovered) ? Color.WhiteSmoke : Color.White;
                        if (renderMode == ToolStripRenderMode.Professional)
                        {
                            fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd;
                            using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical))
                                g.FillPath(br, gp);
                        }
                        else
                        {
                            using (SolidBrush br = new SolidBrush(fill))
                                g.FillPath(br, gp);
                        }
                    }
                    using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace))
                        g.DrawPath(p, gp);
                }
            }
        }
Ejemplo n.º 9
0
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            Color c = SystemColors.AppWorkspace;

            if (UseVS)
            {
                VisualStyleRenderer rndr = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);
                c = rndr.GetColor(ColorProperty.BorderColorHint);
            }

            using (Pen p = new Pen(c))
                using (Pen p2 = new Pen(e.BackColor))
                {
                    Rectangle r  = e.ToolStrip.Bounds;
                    int       x1 = (Mirrored) ? 0 : r.Width - 1 - e.ToolStrip.Padding.Horizontal;
                    int       y1 = (Mirrored) ? 0 : r.Height - 1;
                    if (e.ToolStrip.Orientation == Orientation.Horizontal)
                    {
                        e.Graphics.DrawLine(p, 0, y1, r.Width, y1);
                    }
                    else
                    {
                        e.Graphics.DrawLine(p, x1, 0, x1, r.Height);
                        if (!Mirrored)
                        {
                            for (int i = x1 + 1; i < r.Width; i++)
                            {
                                e.Graphics.DrawLine(p2, i, 0, i, r.Height);
                            }
                        }
                    }
                    foreach (ToolStripItem x in e.ToolStrip.Items)
                    {
                        if (x.IsOnOverflow)
                        {
                            continue;
                        }
                        TabStripButton btn = x as TabStripButton;
                        if (btn == null)
                        {
                            continue;
                        }
                        Rectangle rc    = btn.Bounds;
                        int       x2    = (Mirrored) ? rc.Left : rc.Right;
                        int       y2    = (Mirrored) ? rc.Top : rc.Bottom - 1;
                        int       addXY = (Mirrored) ? 0 : 1;
                        if (e.ToolStrip.Orientation == Orientation.Horizontal)
                        {
                            e.Graphics.DrawLine(p, rc.Left, y2, rc.Right, y2);
                            if (btn.Checked)
                            {
                                e.Graphics.DrawLine(p2, rc.Left + 2 - addXY, y2, rc.Right - 2 - addXY, y2);
                            }
                        }
                        else
                        {
                            e.Graphics.DrawLine(p, x2, rc.Top, x2, rc.Bottom);
                            if (btn.Checked)
                            {
                                e.Graphics.DrawLine(p2, x2, rc.Top + 2 - addXY, x2, rc.Bottom - 2 - addXY);
                            }
                        }
                    }
                }
        }
Ejemplo n.º 10
0
 public SelectedTabChangedEventArgs(TabStripButton tab)
 {
     SelectedTab = tab;
 }