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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
public class AnimTab : TabControl
{
int Oldindex;
int speed = 12;
public AnimTab()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
DoubleBuffered = true;
DrawMode = TabDrawMode.OwnerDrawFixed;
SizeMode = TabSizeMode.Fixed;
Alignment = TabAlignment.Left;
ItemSize = new Size(44, 136);
Appearance = TabAppearance.Normal;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush textBrush;
Font tabFont;
//Clear and draw menu
g.Clear(Color.White);
g.FillRectangle(new SolidBrush(Color.FromArgb(246, 248, 252)), new Rectangle(0, 0, ItemSize.Height + 4, Height));
g.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point(ItemSize.Height + 3, 0), new Point(ItemSize.Height + 3, Height));
//Loop trough menu items
for (int i = 0; i < TabCount; i++)
{
Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
if (i == SelectedIndex)
{
tabFont = new Font("Arial", (float)12.0, FontStyle.Bold, GraphicsUnit.Pixel);
textBrush = new SolidBrush(Color.Black);
ColorBlend myblend = new ColorBlend();
myblend.Colors = new Color[] { Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240), Color.FromArgb(232, 232, 240) };
myblend.Positions = new float[] { 0.0F, 0.5F, 1.0F };
LinearGradientBrush lgbrush = new LinearGradientBrush(x2, Color.Black, Color.Black, 90.0F);
lgbrush.InterpolationColors = myblend;
g.FillRectangle(lgbrush, x2);
g.DrawRectangle(new Pen(Color.FromArgb(170, 187, 204)), x2);
g.SmoothingMode = SmoothingMode.HighQuality;
Point[] p = new Point[] { new Point(ItemSize.Height - 3, GetTabRect(i).Location.Y + 20), new Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 14), new Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 27) };
g.FillPolygon(Brushes.White, p);
g.DrawPolygon(new Pen(Color.FromArgb(170, 187, 204)), p);
}
else
{
tabFont = new Font("Arial", (float)12.0, FontStyle.Regular, GraphicsUnit.Pixel);
textBrush = new System.Drawing.SolidBrush(Color.Gray);
g.FillRectangle(new SolidBrush(Color.FromArgb(246, 248, 252)), x2);
g.DrawLine(new Pen(Color.FromArgb(170, 187, 204)), new Point(x2.Right, x2.Top), new Point(x2.Right, x2.Bottom));
}
//Draw Image
if (ImageList != null && ImageList.Images.Count > TabPages[i].ImageIndex && ImageList.Images[TabPages[i].ImageIndex] != null)
{
g.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(x2.Location.X + 8, x2.Location.Y + GetTabRect(i).Height / 2 - ImageList.Images[TabPages[i].ImageIndex].Height / 2));
}
//Draw String
StringFormat stringFlags = new StringFormat();
stringFlags.Alignment = ImageList == null ? StringAlignment.Center : StringAlignment.Near;
stringFlags.LineAlignment = StringAlignment.Center;
if (ImageList != null) { x2.X += ImageList.ImageSize.Width + 12; }
g.DrawString(TabPages[i].Text, tabFont, textBrush, x2, new StringFormat(stringFlags));
//Draw right line of menu
g.DrawLine(new Pen(Color.FromArgb(200, 200, 250)), new Point(x2.Location.X - 1, x2.Location.Y - 1), new Point(x2.Location.X, x2.Location.Y));
g.DrawLine(new Pen(Color.FromArgb(200, 200, 250)), new Point(x2.Location.X - 1, x2.Bottom - 1), new Point(x2.Location.X, x2.Bottom));
}
//Draw borders
g.DrawRectangle(new Pen(Color.FromArgb(170, 187, 204)), 0, 0, Width - 1, Height - 1);
}
protected override void OnSelected(TabControlEventArgs e)
{
if (Oldindex < e.TabPageIndex)
{
DoAnimationScroll(TabPages[Oldindex], TabPages[e.TabPageIndex], true);
}
else
{
DoAnimationScroll(TabPages[Oldindex], TabPages[e.TabPageIndex], false);
}
}
protected override void OnDeselected(TabControlEventArgs e)
{
Oldindex = e.TabPageIndex;
}
private void DoAnimationScroll(TabPage c1, TabPage c2, bool left)
{
if (c1 == null || c2 == null) { SelectedTab = c2; }
Graphics g = c1.CreateGraphics();
Bitmap p1 = new Bitmap(c1.Width, c1.Height);
Bitmap p2 = new Bitmap(c2.Width, c2.Height);
c1.DrawToBitmap(p1, new Rectangle(0, 0, c1.Width, c1.Height));
c2.DrawToBitmap(p2, new Rectangle(0, 0, c2.Width, c2.Height));
foreach (Control c in c1.Controls) { c.Hide(); }
foreach (Control c in c2.Controls) { c.Hide(); }
int pos2 = 0;
int slide = (c1.Width - (c1.Width % speed)) * (left ? 1 : -1);
int add = speed * (left ? 1 : -1);
for (int a = 0; (a <= slide && slide > 0) || (a >= slide && slide < 0); a += add)
{
pos2 = left ? a - c2.Width : a + c2.Width;
g.DrawImage(p1, new Rectangle(a, 0, c1.Width, c1.Height));
g.DrawImage(p2, new Rectangle(pos2, 0, c2.Width, c2.Height)); // * (left ? -1 : 1)
Application.DoEvents();
}
int a2 = c1.Width;
g.DrawImage(p1, new Rectangle(a2, 0, c1.Width, c1.Height));
g.DrawImage(p2, new Rectangle(a2 - c2.Width, 0, c2.Width, c2.Height));
SelectedTab = c2;
foreach (Control c in c1.Controls) { c.Show(); }
foreach (Control c in c2.Controls) { c.Show(); }
}
public int Speed { get { return speed; } set { if (value > 20 && value < -20) { speed = value; } } }
} |