这里提供的代码是示意图中的第二个进度条的代码。
代码:
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:普通的进度条,带有百分比提示
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/18/2008 08:39:22
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.ComponentModel;
10
using System.Drawing;
11
using System.Drawing.Drawing2D;
12
using System.Drawing.Text;
13
using System.Threading;
14![](/Images/OutliningIndicators/None.gif)
15
namespace Esint.UI.WinFormUI
16![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
17
public class StandardProgressBar:ControlBase
18![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
19
private BackgroundBase barBackground;
20
private float maximum;
21
private float minimum;
22
private string percentMsgFormat;
23
private float value;
24![](/Images/OutliningIndicators/InBlock.gif)
25![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
26
/// 获取或设置进度条的Bar前景色
27
/// </summary>
28
[Category("Appearance"), Description("获取或设置进度条的Bar前景色")]
29
public BackgroundBase BarBackground
30![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
31![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.barBackground; }
32![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.barBackground = value; this.Refresh(); }
33
}
34![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
35
/// 获取或设置进度条的最大值
36
/// </summary>
37
[Category("Appearance"), DefaultValue(100f), Description("获取或设置进度条的最大值")]
38
public float Maximum
39![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
40![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.maximum; }
41![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
42
this.maximum = value;
43
if (this.maximum <= 0)
44![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
45
this.maximum = 100;
46
}
47
if (this.maximum <= this.minimum)
48![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
49
this.maximum = this.minimum + 1;
50
}
51
this.Refresh();
52
}
53
}
54![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
55
/// 获取或设置进度条的最小值
56
/// </summary>
57
[Category("Appearance"), DefaultValue(0f), Description("获取或设置进度条的最小值")]
58
public float Minimum
59![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
60![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.minimum; }
61![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
62
this.minimum = value;
63
if (this.minimum < 0)
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65
this.minimum = 0;
66
}
67
if (this.minimum >= this.maximum)
68![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
69
this.minimum = this.maximum - 1;
70
}
71
this.Refresh();
72
}
73
}
74![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
75
/// 获取或设置进度条的当前值
76
/// </summary>
77
[Category("Appearance"), DefaultValue(0f), Description("获取或设置进度条的当前值")]
78
public float Value
79![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
80![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.value; }
81![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
82
this.value = value;
83
if (this.value < this.minimum)
84![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
85
this.value = this.minimum;
86
}
87
if (this.value > this.maximum)
88![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
89
this.value = this.maximum;
90
}
91
this.Refresh();
92
}
93
}
94![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
95
/// 获取或设置进度条的百分比格式化字符串
96
/// </summary>
97
[Category("Appearance"), DefaultValue("{0}%"), Description("获取或设置进度条的百分比格式化字符串")]
98
public string PercentMsgFormat
99![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
100![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.percentMsgFormat; }
101![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.percentMsgFormat = value; this.Refresh(); }
102
}
103![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
104
/// 获取进度条的进度百分比
105
/// </summary>
106
public string PercentMsg
107![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
108![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{
109
float percent = Value * 100 / Maximum;
110![](/Images/OutliningIndicators/InBlock.gif)
111
return string.Format(PercentMsgFormat, percent.ToString());
112
}
113
}
114![](/Images/OutliningIndicators/InBlock.gif)
115
public StandardProgressBar()
116
:base()
117![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
118
}
119![](/Images/OutliningIndicators/InBlock.gif)
120
protected override void InitializeBackground()
121![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
122
base.InitializeBackground();
123![](/Images/OutliningIndicators/InBlock.gif)
124
this.Background = new BackgroundBase();
125![](/Images/OutliningIndicators/InBlock.gif)
126
Color[] colors =
127![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
128
Color.White,
129
Color.FromArgb(249,249,249),
130
Color.FromArgb(220,220,220),
131
Color.FromArgb(198,198,198),
132
Color.FromArgb(220,220,220),
133
Color.FromArgb(249,249,249),
134
Color.White
135
};
136![](/Images/OutliningIndicators/InBlock.gif)
137
float[] positions =
138![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
139
0.0f,
140
0.2f,
141
0.4f,
142
0.5f,
143
0.6f,
144
0.8f,
145
1.0f
146
};
147![](/Images/OutliningIndicators/InBlock.gif)
148
this.Background.ColorBlend.Colors = colors;
149
this.Background.ColorBlend.Positions = positions;
150![](/Images/OutliningIndicators/InBlock.gif)
151
this.barBackground = new BackgroundBase();
152![](/Images/OutliningIndicators/InBlock.gif)
153
colors = new Color[]
154![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
155
Color.FromArgb(210,255,198),
156
Color.FromArgb(180,255,147),
157
Color.FromArgb(157,233,122),
158
Color.FromArgb(60,132,20),
159
Color.FromArgb(157,233,122),
160
Color.FromArgb(180,255,147),
161
Color.FromArgb(210,255,198)
162
};
163![](/Images/OutliningIndicators/InBlock.gif)
164
positions = new float[]
165![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
166
0.0f,
167
0.2f,
168
0.4f,
169
0.5f,
170
0.6f,
171
0.8f,
172
1.0f
173
};
174![](/Images/OutliningIndicators/InBlock.gif)
175
this.barBackground.ColorBlend.Colors = colors;
176
this.barBackground.ColorBlend.Positions = positions;
177
}
178![](/Images/OutliningIndicators/InBlock.gif)
179
protected override void InitializeSelf()
180![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
181
//base.InitializeSelf();
182![](/Images/OutliningIndicators/InBlock.gif)
183
this.minimum = 0;
184
this.maximum = 100;
185
this.value = 0;
186
this.PercentMsgFormat = "{0}%";
187
this.Name = "StandardProgressBar";
188![](/Images/OutliningIndicators/InBlock.gif)
189
this.MinimumSize = new Size(200,20);
190![](/Images/OutliningIndicators/InBlock.gif)
191
Graphics g = Graphics.FromHwnd(Handle);
192
Size size = g.MeasureString(PercentMsg, this.Font).ToSize();
193
size.Height += 4;
194
if (this.MinimumSize.Width < size.Width + 20)
195![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
196
size.Width += 20;
197
}
198
else
199![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
200
size.Width = this.MinimumSize.Width;
201
}
202
this.MinimumSize = size;
203![](/Images/OutliningIndicators/InBlock.gif)
204
g.Dispose();
205
}
206![](/Images/OutliningIndicators/InBlock.gif)
207![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
208
/// 刷新控件
209
/// </summary>
210
public override void Refresh()
211![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
212
//base.Refresh();
213
ThreadStart method = null;
214
if (this.InvokeRequired)
215![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
216
if (method == null)
217![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
218
method = delegate
219![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
220
Invalidate();
221
};
222
}
223
this.Invoke(method);
224
}
225
}
226![](/Images/OutliningIndicators/InBlock.gif)
227
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
228![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
229
//base.OnPaintBackground(e);
230![](/Images/OutliningIndicators/InBlock.gif)
231
if (!Visible)
232![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
233
return;
234
}
235![](/Images/OutliningIndicators/InBlock.gif)
236
Graphics g = e.Graphics;
237
g.SmoothingMode = SmoothingMode.AntiAlias;
238![](/Images/OutliningIndicators/InBlock.gif)
239
Rectangle rect = this.ClientRectangle;
240
LinearGradientBrush backgroundBrush = new LinearGradientBrush(rect,
241
Color.White, Color.Black, 90f);
242
backgroundBrush.InterpolationColors = Background.ColorBlend;
243![](/Images/OutliningIndicators/InBlock.gif)
244
g.FillRectangle(backgroundBrush, rect);
245![](/Images/OutliningIndicators/InBlock.gif)
246
int progressWidth = (int)((Width - 1) * (Value/Maximum));
247![](/Images/OutliningIndicators/InBlock.gif)
248
//只有当进度大于0的时候才绘制
249
if (progressWidth > 0)
250![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
251
Rectangle progressRect = new Rectangle(1, 0,
252
progressWidth,
253
Height - 1);
254
LinearGradientBrush progressBrush = new LinearGradientBrush(progressRect,
255
Color.White, Color.Black, 90f);
256![](/Images/OutliningIndicators/InBlock.gif)
257
progressBrush.InterpolationColors = BarBackground.ColorBlend;
258![](/Images/OutliningIndicators/InBlock.gif)
259
g.FillRectangle(progressBrush, progressRect);
260![](/Images/OutliningIndicators/InBlock.gif)
261![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (progressBrush != null)
{ progressBrush.Dispose(); }
262
}
263
}
264![](/Images/OutliningIndicators/InBlock.gif)
265
protected override void OnPaintBorder(System.Windows.Forms.PaintEventArgs e)
266![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
267
//base.OnPaintBorder(e);
268
if (!Visible)
269![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
270
return;
271
}
272![](/Images/OutliningIndicators/InBlock.gif)
273
Graphics g = e.Graphics;
274
g.SmoothingMode = SmoothingMode.AntiAlias;
275![](/Images/OutliningIndicators/InBlock.gif)
276
Rectangle rect = this.ClientRectangle;
277
Pen borderPen = new Pen(new SolidBrush(Border.BorderColor), Border.BorderWidth);
278![](/Images/OutliningIndicators/InBlock.gif)
279
rect.Width--;
280
rect.Height--;
281![](/Images/OutliningIndicators/InBlock.gif)
282
g.DrawRectangle(borderPen, rect);
283
}
284![](/Images/OutliningIndicators/InBlock.gif)
285
protected override void OnPaintContent(System.Windows.Forms.PaintEventArgs e)
286![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
287
//base.OnPaintContent(e);
288
if (!Visible)
289![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
290
return;
291
}
292![](/Images/OutliningIndicators/InBlock.gif)
293
Graphics g = e.Graphics;
294
g.SmoothingMode = SmoothingMode.AntiAlias;
295
g.TextRenderingHint = TextRenderingHint.SystemDefault;
296![](/Images/OutliningIndicators/InBlock.gif)
297
Size size = g.MeasureString(PercentMsg, this.Font).ToSize();
298![](/Images/OutliningIndicators/InBlock.gif)
299
PointF txtLocation = new PointF(
300
(float)((Width - size.Width) / 2),
301
(float)((Height - size.Height) / 2));
302![](/Images/OutliningIndicators/InBlock.gif)
303
g.DrawString(PercentMsg, this.Font, new SolidBrush(ForeColor), txtLocation);
304![](/Images/OutliningIndicators/InBlock.gif)
305
}
306
}
307
}
308![](/Images/OutliningIndicators/None.gif)
309![](/Images/OutliningIndicators/None.gif)
下面是进度条的基类代码:
其中涉及到的几个类的代码:
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:基于Control的控件基类
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/16/2008 08:34:42
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.Windows.Forms;
10
using System.ComponentModel;
11
using System.Drawing;
12
using System.Drawing.Drawing2D;
13
using System.Runtime.InteropServices;
14
using System.Threading;
15![](/Images/OutliningIndicators/None.gif)
16
namespace Esint.UI.WinFormUI
17![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
18
[DefaultEvent("Click")]
19
[ComVisible(true)]
20
[DefaultProperty("Text")]
21
public class ControlBase:Control
22![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
23
private ControlBorder border;
24
private BackgroundBase background;
25
private ControlShadow shadow;
26
private bool showShadow;
27
//状态
28
private bool isHovered;
29
private bool isFocused;
30
private bool isFocusedByKey;
31
private bool isKeyDown;
32
private bool isMouseDown;
33![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
private bool isPressed
{ get
{ return isKeyDown || (isMouseDown && isHovered); } }
34![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
35
/// 控件放置的方向(水平、垂直)
36
/// </summary>
37
private Orientation orientation;
38![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
39
/// 原有的控件放置方向
40
/// </summary>
41
private Orientation originalOrientation;
42![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
43
/// 获取或设置控件放置的方向(水平、垂直)
44
/// </summary>
45
[Category("Appearance"), Description("获取或设置控件放置的方向(水平、垂直)")]
46
public Orientation Orientation
47![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
48![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.orientation; }
49
set
50![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
51
this.originalOrientation = this.Orientation;
52
if (value != this.orientation)
53![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
54
TransformOrientation(value);
55
this.orientation = value;
56
}
57
}
58
}
59![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
60
/// 获取或设置控件的边框样式
61
/// </summary>
62
[Category("Appearance"), Description("获取或设置控件的边框样式")]
63
public virtual ControlBorder Border
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65
get
66![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
67
return this.border;
68
}
69
set
70![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
71
this.border = value;
72
}
73
}
74![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
75
/// 获取或设置控件背景样式
76
/// </summary>
77
[Category("Appearance"), Description("获取或设置控件背景样式")]
78
public virtual BackgroundBase Background
79![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
80![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.background; }
81![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.background = value; }
82
}
83![](/Images/OutliningIndicators/InBlock.gif)
84![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
85
/// 获取或设置控件阴影
86
/// </summary>
87
[Category("Appearance"), Description("获取或设置控件阴影")]
88
public virtual ControlShadow Shadow
89![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
90![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.shadow; }
91![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.shadow = value; }
92
}
93![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
94
/// 获取或设置控件是否显示阴影
95
/// </summary>
96
[Category("Appearance"), Description("获取或设置控件是否显示阴影")]
97
public virtual bool ShowShadow
98![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
99![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.showShadow; }
100![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.showShadow = value; }
101
}
102![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
103
/// 获取控件当前是否存在焦点
104
/// </summary>
105
[Browsable(false)]
106
public new bool Focused
107![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
108![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.isFocused; }
109
}
110![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
111
/// 获取控件当前是否被鼠标悬停
112
/// </summary>
113
[Browsable(false)]
114
public bool Hovered
115![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
116![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.isHovered; }
117
}
118![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
119
/// 获取控件是否是由键盘键得到焦点
120
/// </summary>
121
[Browsable(false)]
122
public bool FocusedByKey
123![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
124![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.isFocusedByKey; }
125
}
126![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
127
/// 转换标尺
128
/// </summary>
129
/// <param name="ori"></param>
130
protected void TransformOrientation(Orientation ori)
131![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
132
int width = Width;
133
int height = Height;
134![](/Images/OutliningIndicators/InBlock.gif)
135
if (Orientation != ori)
136![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
137
Height = width;
138
Width = height;
139
}
140
}
141![](/Images/OutliningIndicators/InBlock.gif)
142
public ControlBase()
143![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
144
InitializeStyles();
145
InitializeComponents();
146
}
147![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
148
/// 初始化控件样式和行为
149
/// </summary>
150
protected virtual void InitializeStyles()
151![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
152
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
153
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
154
this.SetStyle(ControlStyles.UserPaint, true);
155
this.SetStyle(ControlStyles.ResizeRedraw, true);
156
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
157
this.SetStyle(ControlStyles.Opaque, false);
158
}
159![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
160
/// 初始化组件
161
/// </summary>
162
protected virtual void InitializeComponents()
163![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
164
//边框
165
InitializeBorder();
166
//背景
167
InitializeBackground();
168
//阴影
169
InitializeShadow();
170
//自身
171
InitializeSelf();
172
}
173![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
174
/// 初始化边框
175
/// </summary>
176
protected virtual void InitializeBorder()
177![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
178
this.border = new ControlBorder(1, Color.Black, BorderCornerMode.Square, 0);
179
this.border.Margin = new Margin();
180
this.border.OnBorderColorChanged += new BorderColorChanged(ControlNeedRefresh);
181
this.border.OnBorderCornerModeChanged += new BorderCornerModeChanged(ControlNeedRefresh);
182
this.border.OnBorderCornerRoundChanged += new BorderCornerRoundChanged(ControlNeedRefresh);
183
this.border.OnBorderMarginChanged += new BorderMarginChanged(ControlNeedRefresh);
184
this.border.OnBorderWidthChanged += new BorderWidthChanged(ControlNeedRefresh);
185
}
186![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
187
/// 初始化背景
188
/// </summary>
189
protected virtual void InitializeBackground()
190![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
191
this.background = new BackgroundBase();
192
//定义参与渐变的色彩
193
Color[] colors =
194![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
195
Color.White,
196
Color.White,
197
Color.FromArgb(228,232,238),
198
Color.FromArgb(202,212,222),
199
Color.FromArgb(228,232,238),
200
Color.White,
201
Color.White
202
};
203
float[] positions =
204![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
205
0.0f,
206
0.1f,
207
0.36f,
208
0.5f,
209
0.64f,
210
0.9f,
211
1.0f
212
};
213
this.background.ColorBlend.Colors = colors;
214
this.background.ColorBlend.Positions = positions;
215
this.background.UseGradientColor = true;
216![](/Images/OutliningIndicators/InBlock.gif)
217
this.background.OnColorBlendChanged += new BackgroundBase.ColorBlendChanged(ControlNeedRefresh);
218
}
219![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
220
/// 初始化阴影
221
/// </summary>
222
protected virtual void InitializeShadow()
223![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
224
this.shadow = new ControlShadow();
225
this.shadow.OnShadowColorChanged += new ShadowColorChanged(ControlNeedRefresh);
226
this.shadow.OnShadowThicknessChanged += new ShadowThicknessChanged(ControlNeedRefresh);
227
this.showShadow = true;
228
}
229![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
230
/// 初始化自身
231
/// </summary>
232
protected virtual void InitializeSelf()
233![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
234
this.Resize += new EventHandler(ControlNeedRefresh);
235
this.Size = new Size(200, 40);
236
this.Orientation = Orientation.Horizontal;
237
}
238![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
239
/// 属性被修改,要重绘控件
240
/// </summary>
241
/// <param name="sender"></param>
242
/// <param name="e"></param>
243
protected virtual void ControlNeedRefresh(object sender, EventArgs e)
244![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
245
this.Refresh();
246
}
247![](/Images/OutliningIndicators/InBlock.gif)
248![](/Images/OutliningIndicators/ContractedSubBlock.gif)
覆写鼠标和键盘事件,控制控件状态(点击、焦点、悬浮、失去焦点)#region 覆写鼠标和键盘事件,控制控件状态(点击、焦点、悬浮、失去焦点)
249![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
250
/// 覆写Click
251
/// </summary>
252
/// <param name="e"></param>
253
protected override void OnClick(EventArgs e)
254![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
255
isKeyDown = isMouseDown = false;
256![](/Images/OutliningIndicators/InBlock.gif)
257
base.OnClick(e);
258
}
259
protected override void OnEnter(EventArgs e)
260![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
261
isFocused = isFocusedByKey = true;
262![](/Images/OutliningIndicators/InBlock.gif)
263
base.OnEnter(e);
264
}
265
protected override void OnLeave(EventArgs e)
266![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
267
base.OnLeave(e);
268
isFocused = isFocusedByKey = isKeyDown = isMouseDown = false;
269
Invalidate();
270
}
271
protected override void OnKeyDown(KeyEventArgs e)
272![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
273
if (e.KeyCode == Keys.Space)
274![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
275
isKeyDown = true;
276
Invalidate();
277
}
278
base.OnKeyDown(e);
279
}
280
protected override void OnKeyUp(KeyEventArgs e)
281![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
282
if (isKeyDown && e.KeyCode == Keys.Space)
283![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
284
isKeyDown = false;
285
Invalidate();
286
}
287
base.OnKeyUp(e);
288
}
289
protected override void OnMouseDown(MouseEventArgs e)
290![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
291
if (!isMouseDown && e.Button == MouseButtons.Left)
292![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
293
isMouseDown = true;
294
isFocusedByKey = false;
295
Invalidate();
296
}
297
base.OnMouseDown(e);
298
}
299
protected override void OnMouseUp(MouseEventArgs e)
300![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
301
if (isMouseDown)
302![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
303
isMouseDown = false;
304
Invalidate();
305
}
306
base.OnMouseUp(e);
307
}
308
protected override void OnMouseMove(MouseEventArgs e)
309![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
310
base.OnMouseMove(e);
311![](/Images/OutliningIndicators/InBlock.gif)
312
if (e.Button != MouseButtons.None)
313![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
314
if (!ClientRectangle.Contains(e.X, e.Y))
315![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
316
if (isHovered)
317![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
318
isHovered = false;
319
Invalidate();
320
}
321
}
322
else if (!isHovered)
323![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
324
isHovered = true;
325
Invalidate();
326
}
327
}
328
}
329
protected override void OnMouseEnter(EventArgs e)
330![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
331
isHovered = true;
332
Invalidate();
333
base.OnMouseEnter(e);
334
}
335
protected override void OnMouseLeave(EventArgs e)
336![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
337
isHovered = false;
338
Invalidate();
339
base.OnMouseLeave(e);
340
}
341
#endregion
342![](/Images/OutliningIndicators/InBlock.gif)
343![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
344
/// 绘制背景
345
/// </summary>
346
/// <param name="pevent"></param>
347
protected override void OnPaintBackground(PaintEventArgs e)
348![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
349
base.OnPaintBackground(e);
350
//如果不可见,则不绘制
351
if (!Visible)
352![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
353
return;
354
}
355
//是否使用渐变色
356
if (background.UseGradientColor)
357![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
358![](/Images/OutliningIndicators/InBlock.gif)
359
Graphics g = e.Graphics;
360
g.SmoothingMode = SmoothingMode.AntiAlias;
361![](/Images/OutliningIndicators/InBlock.gif)
362
int height = Height;
363
int width = Width;
364![](/Images/OutliningIndicators/InBlock.gif)
365
if (this.Orientation == Orientation.Vertical
366
&& this.Orientation != this.originalOrientation)
367![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
368
g.RotateTransform(90);
369
g.TranslateTransform(0, -width + 1);
370
height = Width;
371
width = Height;
372
}
373![](/Images/OutliningIndicators/InBlock.gif)
374
LinearGradientBrush lgb = new LinearGradientBrush(
375
new Point(0, 0),
376
new Point(0, height),
377
Color.Black,
378
Color.White
379
);
380![](/Images/OutliningIndicators/InBlock.gif)
381
lgb.InterpolationColors = background.ColorBlend;
382![](/Images/OutliningIndicators/InBlock.gif)
383
g.FillRectangle(lgb, 0, 0, width, height);
384![](/Images/OutliningIndicators/InBlock.gif)
385![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (lgb != null)
{ lgb.Dispose(); }
386
}
387
}
388![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
389
/// 绘制
390
/// </summary>
391
/// <param name="e"></param>
392
protected override void OnPaint(PaintEventArgs e)
393![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
394
//base.OnPaint(e);
395![](/Images/OutliningIndicators/InBlock.gif)
396
//如果不可见,则不绘制
397
if (!Visible)
398![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
399
return;
400
}
401![](/Images/OutliningIndicators/InBlock.gif)
402
OnPaintBorder(e);
403![](/Images/OutliningIndicators/InBlock.gif)
404
OnPaintContent(e);
405
}
406![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
407
/// 绘制边框
408
/// </summary>
409
/// <param name="e"></param>
410
protected virtual void OnPaintBorder(PaintEventArgs e)
411![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
412
Graphics g = e.Graphics;
413
g.SmoothingMode = SmoothingMode.AntiAlias;
414![](/Images/OutliningIndicators/InBlock.gif)
415
Pen borderPen = new Pen(Border.BorderColor, Border.BorderWidth);
416
Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1);
417
GraphicsPath roundRect = null;
418
//如果是方形拐角,则绘制矩形
419
if (Border.CornerMode == BorderCornerMode.Square)
420![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
421
g.DrawRectangle(borderPen, borderRect);
422
}
423
else
424![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
425
//如果是圆角,则绘制圆角矩形
426
roundRect = DrawHelper.CreateRoundRectangle(borderRect, Border.CornerRound);
427
g.DrawPath(borderPen, roundRect);
428
}
429![](/Images/OutliningIndicators/InBlock.gif)
430![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (borderPen != null)
{ borderPen.Dispose(); }
431![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if (roundRect != null)
{ roundRect.Dispose(); }
432
}
433![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
434
/// 绘制内容
435
/// </summary>
436
/// <param name="e"></param>
437
protected virtual void OnPaintContent(PaintEventArgs e)
438![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
439
}
440![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
441
/// 发送消息
442
/// </summary>
443
/// <param name="msg"></param>
444
/// <param name="wparam"></param>
445
/// <param name="lparam"></param>
446
/// <returns></returns>
447
internal IntPtr SendMessage(int msg, int wparam, int lparam)
448![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
449
return Win32.SendMessage(new HandleRef(this, this.Handle), msg, wparam, lparam);
450
}
451
}
452
}
453![](/Images/OutliningIndicators/None.gif)
454![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:背景基类
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/15/2008 16:53:21
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.Drawing.Drawing2D;
10
using System.Drawing;
11
using System.ComponentModel;
12![](/Images/OutliningIndicators/None.gif)
13
namespace Esint.UI.WinFormUI
14![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
15![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
16
/// 背景类的基类
17
/// </summary>
18
[TypeConverter(typeof(BackgroundBaseConverter))]
19
public class BackgroundBase
20![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
21
public delegate void ColorBlendChanged(object sender, EventArgs e);
22![](/Images/OutliningIndicators/InBlock.gif)
23
public event ColorBlendChanged OnColorBlendChanged;
24![](/Images/OutliningIndicators/InBlock.gif)
25
private ColorBlend blend;
26![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
27
/// 是否使用渐变色
28
/// </summary>
29
private bool useGradientColor;
30![](/Images/OutliningIndicators/InBlock.gif)
31
public BackgroundBase()
32![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
33
this.blend = new ColorBlend();
34![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
Color[] colors = new Color[]
{ Color.White, Color.FromName("Desktop") };
35![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
float[] positions = new float[]
{ 0.0f, 1.0f };
36
this.blend.Colors = colors;
37
this.blend.Positions = positions;
38
this.useGradientColor = true;
39
}
40![](/Images/OutliningIndicators/InBlock.gif)
41
public BackgroundBase(ColorBlend blend)
42![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
43
this.blend = blend;
44
}
45![](/Images/OutliningIndicators/InBlock.gif)
46
public BackgroundBase(Color[] colors, float[] positions)
47
:this(colors,positions,true)
48![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
49![](/Images/OutliningIndicators/InBlock.gif)
50
}
51![](/Images/OutliningIndicators/InBlock.gif)
52
public BackgroundBase(Color[] colors, float[] positions, bool useGradientColor)
53![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
54
this.blend = new ColorBlend();
55
this.blend.Colors = colors;
56
this.blend.Positions = positions;
57
this.useGradientColor = useGradientColor;
58
}
59![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
60
/// 多色渐变中以内插值取代颜色混合的颜色和位置数组
61
/// </summary>
62
[Browsable(false)]
63
public virtual ColorBlend ColorBlend
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.blend; }
66![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
67
if (value != this.blend)
68![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
69
this.blend = value;
70![](/Images/OutliningIndicators/InBlock.gif)
71
if (OnColorBlendChanged != null)
72
OnColorBlendChanged(this, null);
73
}
74
}
75
}
76![](/Images/OutliningIndicators/InBlock.gif)
77![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
78
/// 获取或设置是否能够应用渐变色
79
/// </summary>
80
public virtual bool UseGradientColor
81![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
82
get
83![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
84
return this.useGradientColor;
85
}
86
set
87![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
88
this.useGradientColor = value;
89
}
90
}
91
}
92
}
93![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:控件边框
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/12/2008 08:52:39
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.Drawing;
10
using System.ComponentModel;
11![](/Images/OutliningIndicators/None.gif)
12
namespace Esint.UI.WinFormUI
13![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
14
public delegate void BorderWidthChanged(object sender,EventArgs e);
15
public delegate void BorderColorChanged(object sender,EventArgs e);
16
public delegate void BorderCornerModeChanged(object sender,EventArgs e);
17
public delegate void BorderCornerRoundChanged(object sender,EventArgs e);
18
public delegate void BorderMarginChanged(object sender,EventArgs e);
19![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
20
/// 控件边框
21
/// </summary>
22
[TypeConverter(typeof(ControlBorderConverter))]
23
public class ControlBorder
24![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
25![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Events#region Events
26
public event BorderWidthChanged OnBorderWidthChanged;
27
public event BorderColorChanged OnBorderColorChanged;
28
public event BorderCornerModeChanged OnBorderCornerModeChanged;
29
public event BorderCornerRoundChanged OnBorderCornerRoundChanged;
30
public event BorderMarginChanged OnBorderMarginChanged;
31
#endregion
32![](/Images/OutliningIndicators/InBlock.gif)
33
private float borderWidth;
34
private Color borderColor;
35
//
36
private BorderCornerMode cornerMode;
37
//默认拐角的大小,如果是圆角,则圆角的宽度和高度都是此值
38
private int cornerRound = 10;
39![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
40
/// 自绘边框距控件边界的间隔
41
/// </summary>
42
private Margin borderMargin;
43![](/Images/OutliningIndicators/InBlock.gif)
44
public ControlBorder()
45
:this(1)
46![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
47
}
48![](/Images/OutliningIndicators/InBlock.gif)
49
public ControlBorder(float bWidth)
50
:this(bWidth,Color.Black)
51![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
52
}
53![](/Images/OutliningIndicators/InBlock.gif)
54
public ControlBorder(float bWidth, Color bColor)
55
:this(bWidth,bColor, BorderCornerMode.Round,10)
56![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
57
}
58![](/Images/OutliningIndicators/InBlock.gif)
59
public ControlBorder(float bWidth, Color bColor, BorderCornerMode cMode, int cRound)
60
:this(bWidth,bColor,cMode,cRound,new Margin())
61![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
62
}
63
public ControlBorder(float bWidth, Color bColor, BorderCornerMode cMode, int cRound, Margin margin)
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65
this.borderWidth = bWidth;
66
this.borderColor = bColor;
67
this.cornerMode = cMode;
68
this.cornerRound = cRound;
69
this.borderMargin = new Margin();
70
this.borderMargin.OnTopChanged += new Margin.TopChanged(MarginChanged);
71
this.borderMargin.OnLeftChanged += new Margin.LeftChanged(MarginChanged);
72
this.borderMargin.OnBottomChanged += new Margin.BottomChanged(MarginChanged);
73
this.borderMargin.OnRightChanged += new Margin.RightChanged(MarginChanged);
74
this.borderMargin = margin;
75
}
76![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
77
/// 边框距边界的间隔修改
78
/// </summary>
79
/// <param name="sender"></param>
80
/// <param name="e"></param>
81
void MarginChanged(object sender, EventArgs e)
82![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
83
if (OnBorderMarginChanged != null)
84
OnBorderMarginChanged(this, e);
85
}
86![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
87
/// 边框画笔宽度
88
/// </summary>
89
[Description("获取或设置边框画笔宽度")]
90
public float BorderWidth
91![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
92![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.borderWidth; }
93![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
94
this.borderWidth = value;
95
if (OnBorderWidthChanged != null)
96
OnBorderWidthChanged(this, null);
97
}
98
}
99![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
100
/// 边框颜色
101
/// </summary>
102
[Description("获取或设置边框颜色")]
103
public Color BorderColor
104![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
105![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.borderColor; }
106![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
107
this.borderColor = value;
108
if (OnBorderColorChanged != null)
109
OnBorderColorChanged(this, null);
110
}
111
}
112![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
113
/// 边框Corner的形状(暂时不支持直角,以后再改)
114
/// </summary>
115
[Browsable(false)]
116
[Description("获取或设置边框Corner的形状")]
117
public BorderCornerMode CornerMode
118![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
119![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.cornerMode; }
120![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
121
this.cornerMode = value;
122
if (OnBorderCornerModeChanged != null)
123
OnBorderCornerModeChanged(this, null);
124
}
125
}
126![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
127
/// 边框Corner为圆角时的大小
128
/// </summary>
129
[Description("获取或设置边框Corner为圆角时的大小")]
130
public int CornerRound
131![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
132![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.cornerRound; }
133![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
134
this.cornerRound = value;
135
if (CornerMode != BorderCornerMode.Square)
136![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
137
if (OnBorderCornerRoundChanged != null)
138
OnBorderCornerRoundChanged(this, null);
139
}
140
}
141
}
142![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
143
/// 获取或设置边框距控件边界的间隔
144
/// </summary>
145
[Description("获取或设置边框距控件边界的间隔")]
146
public Margin Margin
147![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
148![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.borderMargin; }
149![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this.borderMargin = value; }
150
}
151
}
152![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
153
/// 边框拐角的类型
154
/// </summary>
155
public enum BorderCornerMode
156![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
157![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
158
/// 直角
159
/// </summary>
160
Square = 1,
161![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
162
/// 圆角
163
/// </summary>
164
Round = 2,
165
}
166
}
167![](/Images/OutliningIndicators/None.gif)
168![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:自绘控件边框与控件的原有边框的间距
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/12/2008 13:14:39
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.ComponentModel;
10![](/Images/OutliningIndicators/None.gif)
11
namespace Esint.UI.WinFormUI
12![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
13![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
14
/// 边框距离控件外框的距离
15
/// </summary>
16
[TypeConverter(typeof(MarginConverter))]
17
public class Margin
18![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
19![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Delegate#region Delegate
20
public delegate void TopChanged(object sender, EventArgs e);
21
public delegate void LeftChanged(object sender, EventArgs e);
22
public delegate void BottomChanged(object sender, EventArgs e);
23
public delegate void RightChanged(object sender, EventArgs e);
24
#endregion
25![](/Images/OutliningIndicators/InBlock.gif)
26![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Events#region Events
27
public event TopChanged OnTopChanged;
28
public event LeftChanged OnLeftChanged;
29
public event BottomChanged OnBottomChanged;
30
public event RightChanged OnRightChanged;
31
#endregion
32![](/Images/OutliningIndicators/InBlock.gif)
33
private int top;
34
private int left;
35
private int bottom;
36
private int right;
37![](/Images/OutliningIndicators/InBlock.gif)
38
public Margin()
39
: this(0, 0)
40![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
41
}
42![](/Images/OutliningIndicators/InBlock.gif)
43
public Margin(int top, int left)
44
: this(top, left, top, left)
45![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
46
}
47![](/Images/OutliningIndicators/InBlock.gif)
48
public Margin(int top, int left, int bottom, int right)
49![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
50
this.top = top;
51
this.left = left;
52
this.bottom = bottom;
53
this.right = right;
54
}
55![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
56
/// 获取或设置顶部间隔
57
/// </summary>
58
public int Top
59![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
60![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.top; }
61![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
62
this.top = value;
63
if (OnTopChanged != null)
64
OnTopChanged(this, null);
65
}
66
}
67![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
68
/// 获取或设置左侧间隔
69
/// </summary>
70
public int Left
71![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
72![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.left; }
73![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
74
this.left = value;
75
if (OnLeftChanged != null)
76
OnLeftChanged(this, null);
77
}
78
}
79![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
80
/// 获取或设置底部间隔
81
/// </summary>
82
public int Bottom
83![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
84![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.bottom; }
85![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
86
this.bottom = value;
87
if (OnBottomChanged != null)
88
OnBottomChanged(this, null);
89
}
90
}
91![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
92
/// 获取或设置右侧间隔
93
/// </summary>
94
public int Right
95![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
96![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.right; }
97![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
98
this.right = value;
99
if (OnRightChanged != null)
100
OnRightChanged(this, null);
101
}
102
}
103
}
104
}
105![](/Images/OutliningIndicators/None.gif)
106![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
// 功能:控件显示的阴影
2
// 描述:
3
// 编码:温伟鹏
4
// 日期:12/12/2008 08:58:58
5![](/Images/OutliningIndicators/None.gif)
6
using System;
7
using System.Collections.Generic;
8
using System.Text;
9
using System.Drawing;
10
using System.ComponentModel;
11![](/Images/OutliningIndicators/None.gif)
12
namespace Esint.UI.WinFormUI
13![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
14
public delegate void ShadowThicknessChanged(object sender,EventArgs e);
15
public delegate void ShadowColorChanged(object sender,EventArgs e);
16![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
17
/// 控件阴影
18
/// </summary>
19
[TypeConverter(typeof(ControlShadowConverter))]
20
public class ControlShadow
21![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22![](/Images/OutliningIndicators/ContractedSubBlock.gif)
Events#region Events
23
public event ShadowColorChanged OnShadowColorChanged;
24
public event ShadowThicknessChanged OnShadowThicknessChanged;
25
#endregion
26![](/Images/OutliningIndicators/InBlock.gif)
27
private int shadowThickness;
28
private Color shadowColor;
29![](/Images/OutliningIndicators/InBlock.gif)
30
public ControlShadow()
31
:this(3,Color.DarkGray)
32![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
33
}
34![](/Images/OutliningIndicators/InBlock.gif)
35
public ControlShadow(Color sdColor)
36
:this(3,sdColor)
37![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
38
}
39![](/Images/OutliningIndicators/InBlock.gif)
40
public ControlShadow(int sdThickness, Color sdColor)
41![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
42
this.shadowThickness = sdThickness;
43
this.shadowColor = sdColor;
44
}
45![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
46
/// 获取或设置阴影厚度
47
/// </summary>
48
[Description("获取或设置阴影的厚度")]
49
public int ShadowThickness
50![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
51![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.shadowThickness; }
52![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
53
this.shadowThickness = value;
54
if (OnShadowThicknessChanged != null)
55
OnShadowThicknessChanged(this, null);
56
}
57
}
58![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
59
/// 获取或设置阴影颜色
60
/// </summary>
61
[Description("获取或设置阴影的颜色")]
62
public Color ShadowColor
63![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this.shadowColor; }
65![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{
66
this.shadowColor = value;
67
if (OnShadowColorChanged != null)
68
OnShadowColorChanged(this, null);
69
}
70
}
71
}
72
}
73![](/Images/OutliningIndicators/None.gif)
这是我从最近写的UI库中选出来的,版本有点旧,大家也可以看出来,代码有点多,同时有些代码也是可有可无的。呵呵。不过懒得改了,大家就当练习吧!