public StripTabControl() { ///添加左边的选项卡选择按钮 LeftStrip = new TabStrip(); LeftStripWidth = 100; ///左侧按键的高度的显示正常是与此按钮有无文字有关 LeftStrip.Dock = DockStyle.Left; LeftStrip.AutoSize = false; LeftStrip.Width = LeftStripWidth; _mainPanel.Dock = DockStyle.Fill; ///初始化TabPages TabPages = new RichList <StripTabPage>(); TabPages.Inserted += new EventHandler <EventArgs <StripTabPage> >(TabPages_Inserted); TabPages.Removed += new EventHandler <EventArgs <StripTabPage> >(TabPages_Removed); this.Controls.Add(_mainPanel); this.Controls.Add(LeftStrip); }
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); } } }