protected override void OnControlRemoved(ControlEventArgs e) { base.OnControlRemoved(e); if (_hideControls.Contains(e.Control)) { _hideControls.Remove(e.Control); } e.Control.TextChanged -= new EventHandler(Control_Changed); e.Control.EnabledChanged -= new EventHandler(Control_Changed); CaptionBasePanel cbp = e.Control as CaptionBasePanel; if (cbp != null) { cbp.IconChanged -= new EventHandler(Control_IconChanged); cbp.WaitingTick -= new EventHandler(Control_IconChanged); } //if (Controls.Count > 0) //{ // SelectedTabControl = SelectableFirstTab(); //} // _tabrects.Remove(e.Control); //TabRectsCalc(); Invalidate(); }
protected override void OnMouseDown(MouseEventArgs e) { //CONTROLER_WIDTH Rectangle r = new Rectangle(Width - CONTROLER_WIDTH - 6, 0, CONTROLER_WIDTH, CONTROLER_WIDTH / 2); if (e.Button == MouseButtons.Right) { if (TabRightOver()) { if (r.Contains(e.Location)) { //メニュー表示 ContextMenuStrip cms = new ContextMenuStrip(); foreach (Control c in Controls) { if (TabVisible(c)) { Image img = null; CaptionBasePanel wc = c as CaptionBasePanel; if (wc != null) { if (wc.Icon != null) { img = wc.Icon.ToBitmap(); } } ToolStripItem item = cms.Items.Add(c.Text, img); item.Tag = c; } } cms.ItemClicked += new ToolStripItemClickedEventHandler(Menu_ItemClicked); cms.Show(this, e.Location); return; } } } else { Control c = TabControlFromPos(e.Location); if (c != null && !IsMouseOnArrow) { SelectedTabControl = c; } } base.OnMouseDown(e); }
protected override void TabSetting(Control c) { if (IsTab) { c.Visible = false; c.Dock = DockStyle.Fill; CaptionBasePanel cp = c as CaptionBasePanel; if (cp != null) { cp.TextVisible = false; cp.FolderOpened = true; cp.FolderOpenedChanged -= new EventHandler <EventArgs>(cp_FolderOpenedChanged); DockingTabPage it = c as DockingTabPage; if (it != null) { it.MainControl.AutoSize = false; } } } else { CaptionBasePanel cp = c as CaptionBasePanel; if (cp != null) { cp.TextVisible = true; cp.FolderOpened = false; cp.FolderOpenedChanged += new EventHandler <EventArgs>(cp_FolderOpenedChanged); DockingTabPage it = c as DockingTabPage; if (it != null) { it.MainControl.AutoSize = false; } } c.Dock = DockStyle.None; if (c.Enabled) { c.Visible = true; } else { c.Visible = false; } } }
protected override void OnControlAdded(ControlEventArgs e) { base.OnControlAdded(e); e.Control.TextChanged += new EventHandler(Control_Changed); e.Control.EnabledChanged += new EventHandler(Control_Changed); CaptionBasePanel cbp = e.Control as CaptionBasePanel; if (cbp != null) { cbp.IconChanged += new EventHandler(Control_IconChanged); cbp.WaitingTick += new EventHandler(Control_IconChanged); } TabSetting(e.Control); // TabRectsCalc(); SelectedTabControl = e.Control; Invalidate(); }
protected virtual void TabSetting(Control c) { if (IsTab) { c.Visible = false; c.Dock = DockStyle.Fill; CaptionBasePanel cp = c as CaptionBasePanel; if (cp != null) { cp.TextVisible = false; cp.FolderOpened = true; InnerTab it = c as InnerTab; if (it != null) { it.MainControl.AutoSize = false; } } } else { CaptionBasePanel cp = c as CaptionBasePanel; if (cp != null) { cp.TextVisible = true; cp.FolderOpened = false; InnerTab it = c as InnerTab; if (it != null) { it.MainControl.AutoSize = true; } } c.Dock = DockStyle.Top; if (TabVisible(c)) { c.Visible = true; } else { c.Visible = false; } } }
/// <summary> /// 描画処理の拡張 /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { int clheight = DisplayRectangle.Height; int clwidth = DisplayRectangle.Width; e.Graphics.TranslateTransform(DisplayRectangle.X, DisplayRectangle.Y); if (IsTab) { Brush foreBrush = new SolidBrush(ButtonLabelForeColor); Color fc = ButtonLabelForeColor; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; int labelHeight = FontHeight + CaptionMargin.Vertical + 6; Control selected = null; Rectangle cr = e.ClipRectangle; e.Graphics.SetClip(new Rectangle(5, 0, clwidth - 10, clheight)); for (int i = Controls.Count - 1; i >= 0; i--) { Control c = Controls[i]; if (TabVisible(c)) { //タブ描画 if (!c.Visible) { if (i >= LeftTab - 1) { Rectangle r = TabRect(LeftTab, c); if (r.Left < clwidth) { Rectangle rt = r; if (i > 0) { rt.X -= 6; rt.Width += 6; } rt.Y += 2; rt.Height -= 2; CaptionBasePanel cbp = c as CaptionBasePanel; Color bc = CaptionGraphics.BlendColor((cbp != null) ? cbp.ButtonLabelBackColor : ButtonLabelBackColor, Color.White, 60); GraphicsPath gp = CaptionGraphics.CreateRoundRectPath(rt, 4, 4, true, true, false, false); CaptionGraphics.DrawShadow(e.Graphics, gp, 1, 3, 20); e.Graphics.FillPath((HoverControl == c) ? new SolidBrush(CaptionGraphics.BlendColor(ClickableColor, bc, 20)) : new SolidBrush(bc), gp); if (cbp != null) { cbp.DrawMarkAndText(e.Graphics, Font, ButtonLabelForeColor, ButtonLabelForeColor, new Point(r.Left + CaptionMargin.Left, rt.Y + CaptionMargin.Top), true); } else { e.Graphics.FillEllipse(foreBrush, r.Left + CaptionMargin.Left, rt.Y + CaptionMargin.Top, FontHeight, FontHeight); TextRenderer.DrawText(e.Graphics, c.Text, Font, new Point(r.Left + (int)(1.5f * FontHeight), rt.Y + CaptionMargin.Top), ButtonLabelForeColor); } } } } else { selected = c; } } } e.Graphics.SetClip(cr); if (selected != null) { CaptionBasePanel cbp = selected as CaptionBasePanel; Rectangle sr = TabRect(LeftTab, selected); GraphicsPath gp = CaptionGraphics.CreateRoundRectPath(sr, 4, 4, true, true, false, false); CaptionGraphics.DrawShadow(e.Graphics, gp); //複雑な形状なので全体再描画 Rectangle r = new Rectangle(6, labelHeight, clwidth - 12, clheight - labelHeight - 6); GraphicsPath gpf = CaptionGraphics.CreateRoundRectPath(r, 2, 2, false, true, true, true); CaptionGraphics.DrawShadow(e.Graphics, gpf); Color blb = ButtonLabelBackColor; Color bbc = BackColor; if (cbp != null) { blb = cbp.ButtonLabelBackColor; bbc = cbp.BackColor; } Brush brush = new SolidBrush((HoverControl == selected) ? ClickableColor : blb); e.Graphics.FillPath(new SolidBrush(bbc), gpf); Pen p = new Pen(blb, 2); e.Graphics.DrawPath(p, gpf); e.Graphics.FillPath(brush, gp); e.Graphics.DrawPath(new Pen(brush, 2), gp); if (Focused) { e.Graphics.DrawPath(new Pen(ButtonLabelFocusBackColor, 1), gp); } Icon ico = null; if (selected is InnerTab) { InnerTab it = selected as InnerTab; Form fm = it.MainControl as Form; if (fm != null) { ico = fm.Icon; } } if (cbp != null) { cbp.DrawMarkAndText(e.Graphics, Font, Focused ? ButtonLabelFocusBackColor : fc, fc, new Point(sr.Left + CaptionMargin.Left, sr.Top + CaptionMargin.Top)); } else { e.Graphics.FillEllipse(new SolidBrush(Focused ? ButtonLabelFocusBackColor : fc), sr.Left + CaptionMargin.Left, CaptionMargin.Top + 1, FontHeight, FontHeight); TextRenderer.DrawText(e.Graphics, selected.Text, Font, new Point(CaptionMargin.Left + sr.Left + (int)(1.5f * FontHeight), CaptionMargin.Top + 1), fc); } } else { //複雑な形状なので全体再描画 Rectangle r = new Rectangle(6, labelHeight, clwidth - 12, clheight - labelHeight - 6); GraphicsPath gpf = CaptionGraphics.CreateRoundRectPath(r, 2, 2, false, true, true, true); CaptionGraphics.DrawShadow(e.Graphics, gpf); e.Graphics.FillPath(Brushes.Gainsboro, gpf); e.Graphics.DrawPath(new Pen(Color.Silver, 2), gpf); } if (TabRightOver()) { //コントローラー描画 Brush brush = new SolidBrush(ButtonLabelBackColor); int ar = CONTROLER_WIDTH / 8; //CONTROLER_WIDTH Rectangle r = new Rectangle(clwidth - CONTROLER_WIDTH - 6, 0, CONTROLER_WIDTH / 2, CONTROLER_WIDTH / 2); GraphicsPath gp = CaptionGraphics.CreateRoundRectPath(r, 4, 4); CaptionGraphics.DrawShadow(e.Graphics, gp); e.Graphics.FillPath((LeftTab > 0) ? brush : Brushes.Silver, gp); e.Graphics.FillPolygon(foreBrush, new Point[] { new Point(r.X + ar, r.Y + r.Height / 2), new Point(r.X + ar * 3, r.Y + r.Height / 2 + ar), new Point(r.X + ar * 3, r.Y + r.Height / 2 - ar) }); r = new Rectangle(clwidth - CONTROLER_WIDTH / 2 - 5, 0, CONTROLER_WIDTH / 2, CONTROLER_WIDTH / 2); gp = CaptionGraphics.CreateRoundRectPath(r, 4, 4); CaptionGraphics.DrawShadow(e.Graphics, gp); e.Graphics.FillPath((RightTab < Controls.Count - 1) ? brush : Brushes.Silver, gp); e.Graphics.FillPolygon(foreBrush, new Point[] { new Point(r.X + ar * 3, r.Y + r.Height / 2), new Point(r.X + ar, r.Y + r.Height / 2 + ar), new Point(r.X + ar, r.Y + r.Height / 2 - ar) }); } } e.Graphics.TranslateTransform(-DisplayRectangle.X, -DisplayRectangle.Y); base.OnPaint(e); }