-
Notifications
You must be signed in to change notification settings - Fork 5
/
OutlookPanelEx.cs
157 lines (141 loc) · 3.47 KB
/
OutlookPanelEx.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
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
151
152
153
154
155
156
157
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Owf.Controls
{
public partial class OutlookPanelEx : Panel
{
int _headerHeight = 25;
string _headerText = "header title";
Color _headerColor1 = Color.FromArgb(89, 135, 214);
Color _headerColor2 = Color.FromArgb(3, 56, 147);
Font _headerFont = new Font("Arial", 12F, System.Drawing.FontStyle.Bold);
Image _icon = null;
Color _iconTransparentColor = Color.White;
[Browsable(true), Category("Owf")]
public string HeaderText
{
get { return _headerText; }
set
{
_headerText = value;
Invalidate();
}
}
[Browsable(true), Category("Owf")]
public Color HeaderColor1
{
get { return _headerColor1; }
set
{
_headerColor1 = value;
Invalidate();
}
}
[Browsable(true), Category("Owf")]
public Color HeaderColor2
{
get { return _headerColor2; }
set
{
_headerColor2 = value;
Invalidate();
}
}
[Browsable(true), Category("Owf")]
public Image Icon
{
get { return _icon; }
set
{
_icon = value;
Invalidate();
}
}
[Browsable(true), Category("Owf")]
public Color IconTransparentColor
{
get { return _iconTransparentColor; }
set
{
_iconTransparentColor = value;
Invalidate();
}
}
//public override Rectangle DisplayRectangle
//{
// get
// {
// Rectangle clientSize = base.DisplayRectangle;
// clientSize.X = 20;
// clientSize.Height -= 20;
// return clientSize;
// }
//}
public OutlookPanelEx()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
this.Padding = new Padding(5, _headerHeight + 4, 5, 4);
}
private void OutlookPanelEx_Paint(object sender, PaintEventArgs e)
{
if (_headerHeight > 1)
{
// Draw border;
DrawBorder(e.Graphics);
// Draw heaeder
DrawHeader(e.Graphics);
// Draw text
DrawText(e.Graphics);
// Draw Icon
DrawIcon(e.Graphics);
}
}
private void DrawBorder(Graphics graphics)
{
using (Pen pen = new Pen(this._headerColor2))
{
graphics.DrawRectangle(pen, 0, 0, this.Width - 1, this.Height - 1);
}
}
private void DrawHeader(Graphics graphics)
{
Rectangle headerRect = new Rectangle(1, 1, this.Width-2, this._headerHeight);
using (Brush brush = new LinearGradientBrush(headerRect, _headerColor1, _headerColor2, LinearGradientMode.Vertical))
{
graphics.FillRectangle(brush, headerRect);
}
}
private void DrawText(Graphics graphics)
{
if (!string.IsNullOrEmpty(this._headerText))
{
SizeF size = graphics.MeasureString(this._headerText, this._headerFont);
using (Brush brush = new SolidBrush(Color.White))
{
graphics.DrawString(this._headerText, this._headerFont, brush, 5, (_headerHeight - size.Height) / 2);
}
}
}
private void DrawIcon(Graphics graphics)
{
if (this._icon != null)
{
Point point = new Point(this.Width - _icon.Width - 2, (_headerHeight - _icon.Height) / 2);
Bitmap bitmap = new Bitmap(_icon);
bitmap.MakeTransparent(_iconTransparentColor);
graphics.DrawImage(bitmap, point);
}
}
}
}