TabStripSystemRenderer.cs
1.6 KB
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Windows.Forms.VisualStyles;
namespace RibbonStyle {
/// <summary>
/// This is just the start of what you would do if you wanted to draw using
/// the theme APIs.
/// </summary>
class TabStripSystemRenderer : ToolStripSystemRenderer {
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);
}
}
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e) {
base.OnRenderItemText(e);
Tab tab = e.Item as Tab;
if (tab != null && tab.Checked) {
Rectangle rect = e.TextRectangle;
ControlPaint.DrawFocusRectangle(e.Graphics, rect);
}
}
}
}