protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            TabStrip        tabStrip = e.ToolStrip as TabStrip;
            ToolStripButton button   = e.Item as ToolStripButton;
            Rectangle       bounds   = new Rectangle(Point.Empty, e.Item.Size);

            if (tabStrip != null)
            {
                System.Windows.Forms.VisualStyles.TabItemState tabState = System.Windows.Forms.VisualStyles.TabItemState.Normal;
                if (button.Checked)
                {
                    tabState |= System.Windows.Forms.VisualStyles.TabItemState.Selected;
                }
                if (button.Selected)
                {
                    tabState |= System.Windows.Forms.VisualStyles.TabItemState.Hot;
                }


                TabRenderer.DrawTabItem(e.Graphics, bounds, tabState);

                if (button.Checked)
                {
                    VisualStyleRenderer vsr           = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot);
                    Padding             borderPadding = button.Padding;
                    borderPadding.Top    += 4;
                    borderPadding.Bottom += 2;
                    borderPadding.Left   -= 2;
                    borderPadding.Right  -= 2;
                    Rectangle rect = LayoutUtils.DeflateRect(bounds, borderPadding);


                    ControlPaint.DrawFocusRectangle(e.Graphics, rect);
                }
            }
            else
            {
                base.OnRenderButtonBackground(e);
            }
        }
        protected override IComponent[] CreateComponentsCore(IDesignerHost host)
        {
            IComponent[] components = base.CreateComponentsCore(host);

            Control                 parentControl         = null;
            ControlDesigner         parentControlDesigner = null;
            TabStrip                tabStrip  = null;
            IComponentChangeService changeSvc = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));


            // fish out the parent we're adding the TabStrip to.
            if (components.Length > 0 && components[0] is TabStrip)
            {
                tabStrip = components[0] as TabStrip;

                ITreeDesigner tabStripDesigner = host.GetDesigner(tabStrip) as ITreeDesigner;
                parentControlDesigner = tabStripDesigner.Parent as ControlDesigner;
                if (parentControlDesigner != null)
                {
                    parentControl = parentControlDesigner.Control;
                }
            }

            // Create a ControlSwitcher on the same parent.

            if (host != null)
            {
                TabPageSwitcher controlSwitcher = null;

                DesignerTransaction t = null;
                try {
                    try {
                        t = host.CreateTransaction("add tabswitcher");
                    }
                    catch (CheckoutException ex) {
                        if (ex == CheckoutException.Canceled)
                        {
                            return(components);
                        }
                        throw ex;
                    }
                    MemberDescriptor controlsMember = TypeDescriptor.GetProperties(parentControlDesigner)["Controls"];
                    controlSwitcher = host.CreateComponent(typeof(TabPageSwitcher)) as TabPageSwitcher;

                    if (changeSvc != null)
                    {
                        changeSvc.OnComponentChanging(parentControl, controlsMember);
                        changeSvc.OnComponentChanged(parentControl, controlsMember, null, null);
                    }

                    Dictionary <string, object> propertyValues = new Dictionary <string, object>();
                    propertyValues["Location"] = new Point(tabStrip.Left, tabStrip.Bottom + 3);
                    propertyValues["TabStrip"] = tabStrip;

                    SetProperties(controlSwitcher, propertyValues, host);
                }
                finally {
                    if (t != null)
                    {
                        t.Commit();
                    }
                }

                if (controlSwitcher != null)
                {
                    IComponent[] newComponents = new IComponent[components.Length + 1];
                    Array.Copy(components, newComponents, components.Length);
                    newComponents[newComponents.Length - 1] = controlSwitcher;
                    return(newComponents);
                }
            }

            return(components);
        }
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            TabStrip tabStrip = e.ToolStrip as TabStrip;
            Tab      tab      = e.Item as Tab;

            if (tab == null)
            {
                base.OnRenderButtonBackground(e);
                return;
            }
            Rectangle bounds = new Rectangle(Point.Empty, e.Item.Size);
            Graphics  g      = e.Graphics;


            // we want an even rise in the angle, for every pixel we have to go up,
            // we need to go over one pixel.  This will give us a straig

            if (tabStrip != null)
            {
                Point[] tabPolygonPoints = new Point[] {
                    new Point(0, bounds.Bottom),               // lower left hand corner
                    new Point(tab.Height, bounds.Top),         // upper left hand corner
                    new Point(bounds.Right - 1, bounds.Top),   // upper right hand corner
                    new Point(bounds.Right - 1, bounds.Bottom) // lower right hand corner
                };

                Point[] fillTabPolygonPoints = new Point[] {
                    tabPolygonPoints[BOTTOM_LEFT],
                    new Point(tabPolygonPoints[TOP_LEFT].X - 2, tabPolygonPoints[TOP_LEFT].Y + 2),
                    new Point(tabPolygonPoints[TOP_LEFT].X + 2, tabPolygonPoints[TOP_LEFT].Y),
                    tabPolygonPoints[TOP_RIGHT],
                    tabPolygonPoints[BOTTOM_RIGHT]
                };


                Color startColor = ColorTable.MenuStripGradientEnd;
                Color endColor   = ColorTable.MenuStripGradientBegin;



                if (tab.Selected && !tab.Checked)
                {
                    startColor = ColorTable.ButtonSelectedGradientBegin;
                    endColor   = ColorTable.ButtonSelectedGradientEnd;
                }
                using (Brush b = new LinearGradientBrush(bounds, startColor, endColor, LinearGradientMode.Vertical)) {
                    g.FillPolygon(b, fillTabPolygonPoints);
                }



                using (Pen outerBlueBorderPen = new Pen(ColorTable.ButtonSelectedBorder)) {
                    using (Pen innerWhiteBorderPen = new Pen(ColorTable.GripLight)) {
                        //
                        // draw left edge
                        //
                        //   Bw
                        //  Bw
                        // Bw
                        Point edgeStart = tabPolygonPoints[BOTTOM_LEFT];
                        Point edgeStop  = tabPolygonPoints[TOP_LEFT];
                        edgeStop.Offset(-2, 2); // stop one pixels early.

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);

                        // draw white shadow line along left edge
                        edgeStart.Offset(1, 0);
                        edgeStop.Offset(1, 0);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);

                        //
                        // draw rounded corner
                        //       TOP_LEFT
                        //          v
                        //          [BBBBBBBBBBBBBBBBBBBBBB] <- top edge
                        //        BB[wwwwwwwwwwwwwwwwwwwwww] <- top edge shadow  (row 2)
                        //      BBww                                             (row 3)
                        //     Bww                                               (row 4)


                        // draw row 2
                        edgeStart = tabPolygonPoints[TOP_LEFT];
                        edgeStart.Offset(0, 1);
                        edgeStop    = edgeStart;
                        edgeStop.X += 1;

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);

                        // draw row 3
                        edgeStart.Offset(-2, 1);
                        edgeStop.Offset(-2, 1);
                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                        edgeStart.Offset(2, 0);
                        edgeStop.Offset(2, 0);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);

                        // draw row 4
                        edgeStart.Offset(-2, 1);
                        edgeStop.Offset(-2, 1);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);

                        //
                        // draw top edge
                        //
                        //       TOP_LEFT
                        //          v
                        //          [BBBBBBBBBBBBBBBBBBBBBB] <- top edge
                        //        BB[wwwwwwwwwwwwwwwwwwwwww] <- top edge shadow  (row 2)


                        edgeStart = tabPolygonPoints[TOP_LEFT];
                        edgeStop  = tabPolygonPoints[TOP_RIGHT];

                        // scoot over two pixels
                        edgeStart.Offset(2, 0);
                        edgeStop.Offset(-2, 0);

                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);

                        // scoot down to paint white shadow line
                        edgeStart.Offset(0, 1);
                        edgeStop.Offset(0, 1);
                        g.DrawLine(innerWhiteBorderPen, edgeStart, edgeStop);


                        //
                        // draw right edge
                        //          TOP_RIGHT
                        //              v
                        //            bB
                        //              bB
                        //              bB
                        //              bB

                        edgeStart = new Point(tabPolygonPoints[TOP_RIGHT].X, tabPolygonPoints[TOP_RIGHT].Y + 2);
                        edgeStop  = tabPolygonPoints[BOTTOM_RIGHT];

                        // draw dark blue lines
                        g.DrawLine(outerBlueBorderPen, edgeStart, edgeStop);
                        using (Brush b = new SolidBrush(outerBlueBorderPen.Color)) {
                            g.FillRectangle(b, new Rectangle(edgeStart.X - 1, edgeStart.Y - 1, 1, 1));
                        }

                        // draw light blue lines
                        using (Pen innerBlueBorderPen = new Pen(ColorTable.ButtonPressedHighlight)) {
                            edgeStart.Offset(-1, 0);
                            edgeStop.Offset(-1, 0);
                            g.DrawLine(innerBlueBorderPen, edgeStart, edgeStop);
                            using (Brush b = new SolidBrush(innerBlueBorderPen.Color)) {
                                g.FillRectangle(b, new Rectangle(edgeStart.X - 1, edgeStart.Y - 1, 1, 1));
                            }
                        }
                    }
                }


                tabPolygonPoints[0].Offset(1, 0);
                tabPolygonPoints[1].Offset(1, 0);
            }
            else
            {
                base.OnRenderButtonBackground(e);
            }
        }
示例#4
0
 public TabStripLayoutEngine(TabStrip tabStrip) {
     this.tabStrip = tabStrip;
 }
示例#5
0
 public TabStripLayoutEngine(TabStrip tabStrip)
 {
     this.tabStrip = tabStrip;
 }