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

            if (tab != null && tabStrip != null)
            {
                System.Windows.Forms.VisualStyles.TabItemState tabState = System.Windows.Forms.VisualStyles.TabItemState.Normal;
                if (tab.Checked)
                {
                    tabState |= System.Windows.Forms.VisualStyles.TabItemState.Selected;
                }
                if (tab.Selected)
                {
                    tabState |= System.Windows.Forms.VisualStyles.TabItemState.Hot;
                }
                TabRenderer.DrawTabItem(e.Graphics, bounds, tabState);
            }
            else
            {
                base.OnRenderButtonBackground(e);
            }
        }
示例#2
0
        /// <summary>
        /// this method is called when dragging a TabStrip off the toolbox.
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        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;
                    }

                    // create a TabPageSwitcher and add it to the same parent as the TabStrip
                    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);
                    }

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

                    // set the property values
                    SetProperties(controlSwitcher, propertyValues, host);
                }
                finally {
                    if (t != null)
                    {
                        t.Commit();
                    }
                }

                // add the TabPageSwitcher to the list of components that we've created
                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);
        }
        /// <summary>
        /// Control when the background of the Tab is painting.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            TabStrip tabStrip  = e.ToolStrip as TabStrip;
            Tab      tab       = e.Item as Tab;
            int      i_opacity = tab.i_opacity;

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

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            int textwidth  = Convert.ToInt16(g.MeasureString(tab.Text, tab.Font).Width) - Convert.ToInt16(tab.Text.Length / 3);
            int textheight = Convert.ToInt16(g.MeasureString(tab.Text, tab.Font).Height);

            if (tabStrip != null)
            {
                #region Tab Selected and NOT active
                if (tab.b_selected & !tab.b_active)
                {
                    #region Show Lateral Gradients
                    Rectangle ri = bounds;
                    ri.Width = (tab.Width - textwidth) / 2;
                    ri.X    += 2; ri.Width -= 2;
                    Color C0i = BaseColor; int c_origin = 255; C0i = SetTransparency(C0i, 0);
                    Color CFi             = HaloColor; c_origin = 255; CFi = SetTransparency(CFi, c_origin - i_opacity);
                    LinearGradientBrush b = new LinearGradientBrush(ri, C0i, CFi, LinearGradientMode.BackwardDiagonal);
                    g.FillRectangle(b, ri.X, ri.Y, ri.Width, ri.Height);
                    int offset = bounds.Width - ri.Width - 1;
                    ri.Location = new Point(offset, 1);
                    b           = new LinearGradientBrush(ri, C0i, CFi, LinearGradientMode.ForwardDiagonal);
                    g.FillRectangle(b, offset, ri.Y, ri.Width, ri.Height);
                    #endregion

                    #region Show Central Gradient
                    Rectangle r = bounds;
                    r.X     += 2; r.Width -= 2;
                    r.Height = r.Height / 2;
                    Color C0 = BaseColor; c_origin = 255; C0 = SetTransparency(C0, c_origin - i_opacity);
                    Color CF = HaloColor; c_origin = 255; CF = SetTransparency(CF, c_origin - i_opacity);
                    b = new LinearGradientBrush(r, C0, CF, LinearGradientMode.Vertical);
                    g.FillRectangle(b, r.X, r.Y + r.Height + 1, r.Width - r.X, r.Height);
                    #endregion

                    #region Show Vertical Side Lines
                    int Offs = 0;
                    X0 = 0; XF = tab.Width + X0;
                    YF = tab.Height + Y0; Y0 = 0;
                    Point     P0   = new Point(X0, Y0);
                    Point     PF   = new Point(X0, YF / 2);
                    Color     C0sl = this.OnBackColor; C0sl = SetTransparency(C0sl, 0);
                    Color     CFsl = Color.White;
                    Rectangle rsl  = new Rectangle(X0, Y0 + Offs, X0 + 1, YF / 2);
                    b = new LinearGradientBrush(rsl, C0sl, CFsl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, X0, Y0 + Offs, rsl.Width, rsl.Height);
                    rsl = new Rectangle(X0, YF / 2 - 1, X0 + 1, YF - Offs);
                    b   = new LinearGradientBrush(rsl, CFsl, C0sl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, X0, YF / 2 - 1, rsl.Width, rsl.Height);

                    Rectangle rsr = new Rectangle(XF - 2, Y0 + Offs, XF - 1, YF / 2);
                    b = new LinearGradientBrush(rsr, C0sl, CFsl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, XF - 1, Y0 + Offs, rsr.Width, rsr.Height);
                    rsr = new Rectangle(XF - 2, YF / 2 - 1, XF - 1, YF - Offs);
                    b   = new LinearGradientBrush(rsr, CFsl, C0sl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, XF - 1, YF / 2 - 1, rsr.Width, rsr.Height);
                    #endregion

                    #region Show Border
                    X0 = 0; XF = tab.Width + X0;
                    Y0 = 0; YF = tab.Height + Y0;
                    P0 = new Point(X0, Y0);
                    PF = new Point(X0, Y0 + YF - 15);
                    Color BorderColor = BaseColor; c_origin = 255; BorderColor = SetTransparency(BorderColor, c_origin - i_opacity);
                    Pen   PBorder     = new Pen(BorderColor);
                    X = X0; Y = Y0; i_Zero = 270; D = 1; T = 5;
                    DrawArc(0);
                    g.DrawPath(PBorder, path);
                    X = X0; Y = Y0; i_Zero = 270; D = 1; T = 5;
                    DrawArc(1);
                    Color IBC = Color.White; c_origin = 164; IBC = SetTransparency(IBC, c_origin - i_opacity);
                    PBorder = new Pen(IBC);
                    g.DrawPath(PBorder, path);
                    #endregion
                }
                #endregion

                else if (tab.b_active & !tab.b_selected)
                {
                    #region Show Upper Rectangle
                    Rectangle upblock = new Rectangle(8, 3, bounds.Width - 16, 4);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(245, 250, 255)), upblock);
                    #endregion

                    #region Show Bottom Rectangle
                    Color     CFsl    = this.BaseColor;
                    Color     C0sl    = Color.FromArgb(CFsl.R + 19, CFsl.G + 15, CFsl.B + 10);
                    Rectangle doblock = new Rectangle(6, 3, bounds.Width - 12, bounds.Height);
                    Brush     b       = new LinearGradientBrush(doblock, C0sl, CFsl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, doblock);
                    #endregion

                    #region Show Line Borders
                    Pen b2 = Pens.White; Pen b3 = Pens.White; Pen b4 = Pens.White;
                    int R0 = this.BaseColor.R;
                    int G0 = this.BaseColor.G;
                    int B0 = this.BaseColor.B;
                    int TX0 = 0; int TY0 = 0; int TXF = bounds.Width; int TYF = bounds.Height;
                    if (R0 != 0 & G0 != 0 & B0 != 0)
                    {
                        if (BaseColor.GetBrightness() < 0.5) //Dark Colors
                        {
                            b2 = new Pen(Color.FromArgb(R0 - 22, G0 - 11, B0));
                            b3 = new Pen(Color.FromArgb(R0 + 18, G0 + 25, B0));
                            b4 = new Pen(Color.FromArgb(R0, G0, B0));
                        }
                        else
                        {
                            b2 = new Pen(Color.FromArgb(R0 - 74, G0 - 49, B0 - 15));
                            b3 = new Pen(Color.FromArgb(R0 - 8, G0 - 24, B0 + 10));
                            b4 = new Pen(Color.FromArgb(R0, G0, B0));
                        }


                        DrawTab(TX0, TY0, TXF, TYF);
                        g.DrawPath(b2, path);
                        DrawTab(TX0 + 1, TY0 + 1, TXF - 1, TYF);
                        g.DrawPath(b3, path);
                        DrawTab(TX0 + 2, TY0 + 2, TXF - 2, TYF);
                        g.DrawPath(b4, path);
                    }
                    #endregion

                    #region Show Shadow
                    Point P0 = new Point(bounds.Right - 5, 3); Point PF = new Point(bounds.Right - 5, bounds.Height - 2);
                    Pen   ps = new Pen(SetTransparency(Color.Black, 20));
                    g.DrawLine(ps, P0, PF);
                    P0 = new Point(bounds.Right - 4, 4); PF = new Point(bounds.Right - 4, bounds.Height - 1);
                    ps = new Pen(SetTransparency(Color.Black, 10));
                    g.DrawLine(ps, P0, PF);
                    #endregion
                }
                else if (tab.b_active & tab.b_selected)
                {
                    #region Show Upper Rectangle
                    Rectangle upblock = new Rectangle(8, 3, bounds.Width - 16, 4);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(245, 250, 255)), upblock);
                    #endregion

                    #region Show Bottom Rectangle
                    Color     CFsl    = this.BaseColor;
                    Color     C0sl    = Color.FromArgb(CFsl.R + 19, CFsl.G + 15, CFsl.B + 10);
                    Rectangle doblock = new Rectangle(6, 3, bounds.Width - 12, bounds.Height);
                    Brush     b       = new LinearGradientBrush(doblock, C0sl, CFsl, LinearGradientMode.Vertical);
                    g.FillRectangle(b, doblock);
                    #endregion

                    #region Show Line Borders
                    Pen b2 = Pens.White; Pen b3 = Pens.White; Pen b4 = Pens.White;
                    int R0 = this.BaseColor.R;
                    int G0 = this.BaseColor.G;
                    int B0 = this.BaseColor.B;
                    int TX0 = 0; int TY0 = 0; int TXF = bounds.Width; int TYF = bounds.Height;
                    if (R0 != 0 & G0 != 0 & B0 != 0)
                    {
                        if (BaseColor.GetBrightness() < 0.5) //Dark Colors
                        {
                            b2 = new Pen(Color.FromArgb(R0 - 26, G0 - 14, B0 - 3));
                            b3 = new Pen(Color.FromArgb(R0 + 18, G0 + 25, B0));
                            b4 = new Pen(Color.FromArgb(R0, G0, B0));
                        }
                        else
                        {
                            b2 = new Pen(Color.FromArgb(R0 - 74, G0 - 49, B0 - 15));
                            b3 = new Pen(Color.FromArgb(R0 - 8, G0 - 24, B0 + 10));
                            b4 = new Pen(Color.FromArgb(R0, G0, B0));
                        }


                        DrawTab(TX0, TY0, TXF, TYF);
                        g.DrawPath(b2, path);
                        DrawTab(TX0 + 1, TY0 + 1, TXF - 1, TYF);
                        g.DrawPath(b3, path);
                        DrawTab(TX0 + 2, TY0 + 2, TXF - 2, TYF);
                        g.DrawPath(b4, path);
                    }
                    #endregion

                    #region Show Shadow
                    Point P0 = new Point(bounds.Right - 5, 3); Point PF = new Point(bounds.Right - 5, bounds.Height - 2);
                    Pen   ps = new Pen(SetTransparency(Color.Black, 20));
                    g.DrawLine(ps, P0, PF);
                    P0 = new Point(bounds.Right - 4, 4); PF = new Point(bounds.Right - 4, bounds.Height - 1);
                    ps = new Pen(SetTransparency(Color.Black, 10));
                    g.DrawLine(ps, P0, PF);
                    #endregion

                    #region Show Halo
                    Color CH = halocolor; int c_origin = 255; CH = SetTransparency(CH, c_origin - i_opacity);
                    DrawHalo(TX0, TY0, TXF, TYF);
                    g.DrawPath(new Pen(CH), path);
                    DrawHalo(TX0 + 1, TY0 + 1, TXF + 1, TYF);
                    g.DrawPath(new Pen(CH), path);
                    #endregion
                }
            }
            else
            {
                base.OnRenderButtonBackground(e);
            }
        }