-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTab.cs
96 lines (81 loc) · 2.59 KB
/
MyTab.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//Custom tab control because DarkUI doesn't have one
using System.Drawing;
using System.Windows.Forms;
namespace KiSSLab
{
class MyTab : TabControl
{
public event TabControlEventHandler CloseClicked;
public bool CloseButtons { get; set; }
public MyTab()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
//if (CloseButtons)
{
this.Padding = new Point(32, 0);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (!Visible)
return;
e.Graphics.Clear(DarkUI.Config.Colors.GreyBackground);
for (var i = 0; i < this.TabCount; i++)
DrawTab(e.Graphics, this.TabPages[i], i);
}
internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
{
var recBounds = this.GetTabRect(nIndex);
var tabTextArea = (RectangleF)this.GetTabRect(nIndex);
recBounds.Inflate(0, 1);
var bSelected = (this.SelectedIndex == nIndex);
var fill = new SolidBrush(DarkUI.Config.Colors.BlueBackground);
var dark = new Pen(DarkUI.Config.Colors.DarkBlueBorder);
var light = new Pen(DarkUI.Config.Colors.LightBlueBorder);
var text = new SolidBrush(DarkUI.Config.Colors.LightText);
if (bSelected)
{
g.FillRectangle(fill, recBounds);
g.DrawLine(dark, recBounds.Right, recBounds.Top, recBounds.Right, recBounds.Bottom);
g.DrawLine(light, recBounds.Left, recBounds.Top, recBounds.Right, recBounds.Top);
g.DrawLine(light, recBounds.Left, recBounds.Top, recBounds.Left, recBounds.Bottom);
}
tabTextArea.Offset(8, 0);
var stringFormat = new StringFormat()
{
Alignment = StringAlignment.Near,
LineAlignment = StringAlignment.Center,
};
g.DrawString(tabPage.Text, Font, text, tabTextArea, stringFormat);
if (bSelected && CloseButtons)
{
stringFormat.Alignment = StringAlignment.Far;
tabTextArea.Offset(-10, 0);
g.DrawString("×", Font, text, tabTextArea, stringFormat);
}
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
if (!CloseButtons)
return;
if (CloseClicked == null)
return;
var recBounds = this.GetTabRect(this.SelectedIndex);
var closeBox = new Rectangle(recBounds.Right - 10, recBounds.Top, 10, recBounds.Height);
if (closeBox.Contains(e.Location))
CloseClicked(this, new TabControlEventArgs(this.SelectedTab, this.SelectedIndex, TabControlAction.Deselecting));
}
}
class MyPanel : Panel
{
public MyPanel() : base()
{
this.DoubleBuffered = true;
}
}
}