Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
HZH_Controls
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit aefbc688
由
HZH
编写于
2019-08-23 08:58:52 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
add Wave and WaveChart
1 个父辈
97646b42
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
467 行增加
和
0 行删除
HZH_Controls/HZH_Controls/Controls/Wave/UCWave.cs
HZH_Controls/HZH_Controls/Controls/Wave/UCWaveChart.cs
HZH_Controls/HZH_Controls/HZH_Controls.csproj
HZH_Controls/Test/Form2.Designer.cs
HZH_Controls/Test/Form2.cs
HZH_Controls/Test/FrmTestListView.cs
HZH_Controls/HZH_Controls/Controls/Wave/UCWave.cs
0 → 100644
查看文件 @
aefbc68
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Linq
;
using
System.Text
;
using
System.Windows.Forms
;
namespace
HZH_Controls.Controls
{
public
class
UCWave
:
Control
{
private
Color
m_waveColor
=
Color
.
FromArgb
(
73
,
119
,
232
);
[
Description
(
"波纹颜色"
),
Category
(
"自定义"
)]
public
Color
WaveColor
{
get
{
return
m_waveColor
;
}
set
{
m_waveColor
=
value
;
}
}
private
int
m_waveWidth
=
200
;
/// <summary>
/// 为方便计算,强制使用10的倍数
/// </summary>
[
Description
(
"波纹宽度(为方便计算,强制使用10的倍数)"
),
Category
(
"自定义"
)]
public
int
WaveWidth
{
get
{
return
m_waveWidth
;
}
set
{
m_waveWidth
=
value
;
m_waveWidth
=
m_waveWidth
/
10
*
10
;
intLeftX
=
value
*
-
1
;
}
}
private
int
m_waveHeight
=
30
;
/// <summary>
/// 波高
/// </summary>
[
Description
(
"波高"
),
Category
(
"自定义"
)]
public
int
WaveHeight
{
get
{
return
m_waveHeight
;
}
set
{
m_waveHeight
=
value
;
}
}
private
int
m_waveSleep
=
50
;
/// <summary>
/// 波运行速度(运行时间间隔,毫秒)
/// </summary>
[
Description
(
"波运行速度(运行时间间隔,毫秒)"
),
Category
(
"自定义"
)]
public
int
WaveSleep
{
get
{
return
m_waveSleep
;
}
set
{
if
(
value
<=
0
)
return
;
m_waveSleep
=
value
;
if
(
timer
!=
null
)
{
timer
.
Enabled
=
false
;
timer
.
Interval
=
value
;
timer
.
Enabled
=
true
;
}
}
}
Timer
timer
=
new
Timer
();
int
intLeftX
=
-
200
;
public
UCWave
()
{
this
.
Size
=
new
Size
(
600
,
100
);
this
.
SetStyle
(
ControlStyles
.
AllPaintingInWmPaint
,
true
);
this
.
SetStyle
(
ControlStyles
.
DoubleBuffer
,
true
);
this
.
SetStyle
(
ControlStyles
.
ResizeRedraw
,
true
);
this
.
SetStyle
(
ControlStyles
.
Selectable
,
true
);
this
.
SetStyle
(
ControlStyles
.
SupportsTransparentBackColor
,
true
);
this
.
SetStyle
(
ControlStyles
.
UserPaint
,
true
);
timer
.
Interval
=
m_waveSleep
;
timer
.
Tick
+=
timer_Tick
;
this
.
VisibleChanged
+=
UCWave_VisibleChanged
;
}
void
UCWave_VisibleChanged
(
object
sender
,
EventArgs
e
)
{
timer
.
Enabled
=
this
.
Visible
;
}
void
timer_Tick
(
object
sender
,
EventArgs
e
)
{
intLeftX
-=
10
;
if
(
intLeftX
==
m_waveWidth
*
-
2
)
intLeftX
=
m_waveWidth
*
-
1
;
this
.
Refresh
();
}
protected
override
void
OnPaint
(
PaintEventArgs
e
)
{
base
.
OnPaint
(
e
);
var
g
=
e
.
Graphics
;
g
.
SetGDIHigh
();
List
<
Point
>
lst1
=
new
List
<
Point
>();
List
<
Point
>
lst2
=
new
List
<
Point
>();
int
m_intX
=
intLeftX
;
while
(
true
)
{
lst1
.
Add
(
new
Point
(
m_intX
,
1
));
lst1
.
Add
(
new
Point
(
m_intX
+
m_waveWidth
/
2
,
m_waveHeight
));
lst2
.
Add
(
new
Point
(
m_intX
+
m_waveWidth
/
4
,
1
));
lst2
.
Add
(
new
Point
(
m_intX
+
m_waveWidth
/
4
+
m_waveWidth
/
2
,
m_waveHeight
));
m_intX
+=
m_waveWidth
;
if
(
m_intX
>
this
.
Width
+
m_waveWidth
)
break
;
}
GraphicsPath
path1
=
new
GraphicsPath
();
path1
.
AddCurve
(
lst1
.
ToArray
(),
0.5F
);
path1
.
AddLine
(
this
.
Width
+
1
,
-
1
,
this
.
Width
+
1
,
this
.
Height
);
path1
.
AddLine
(
this
.
Width
+
1
,
this
.
Height
,
-
1
,
this
.
Height
);
path1
.
AddLine
(-
1
,
this
.
Height
,
-
1
,
-
1
);
GraphicsPath
path2
=
new
GraphicsPath
();
path2
.
AddCurve
(
lst2
.
ToArray
(),
0.5F
);
path2
.
AddLine
(
this
.
Width
+
1
,
-
1
,
this
.
Width
+
1
,
this
.
Height
);
path2
.
AddLine
(
this
.
Width
+
1
,
this
.
Height
,
-
1
,
this
.
Height
);
path2
.
AddLine
(-
1
,
this
.
Height
,
-
1
,
-
1
);
g
.
FillPath
(
new
SolidBrush
(
Color
.
FromArgb
(
220
,
m_waveColor
.
R
,
m_waveColor
.
G
,
m_waveColor
.
B
)),
path1
);
g
.
FillPath
(
new
SolidBrush
(
Color
.
FromArgb
(
220
,
m_waveColor
.
R
,
m_waveColor
.
G
,
m_waveColor
.
B
)),
path2
);
}
}
}
HZH_Controls/HZH_Controls/Controls/Wave/UCWaveChart.cs
0 → 100644
查看文件 @
aefbc68
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Linq
;
using
System.Text
;
using
System.Windows.Forms
;
namespace
HZH_Controls.Controls
{
public
class
UCWaveWithSource
:
UCControlBase
{
private
int
m_waveActualWidth
=
50
;
private
int
m_waveWidth
=
50
;
[
Description
(
"波形宽度"
),
Category
(
"自定义"
)]
public
int
WaveWidth
{
get
{
return
m_waveWidth
;
}
set
{
if
(
value
<=
0
)
return
;
m_waveWidth
=
value
;
ResetWaveCount
();
Refresh
();
}
}
private
int
m_sleepTime
=
1000
;
/// <summary>
/// 波运行速度(运行时间间隔,毫秒)
/// </summary>
[
Description
(
"运行速度(运行时间间隔,毫秒)"
),
Category
(
"自定义"
)]
public
int
SleepTime
{
get
{
return
m_sleepTime
;
}
set
{
if
(
value
<=
0
)
return
;
m_sleepTime
=
value
;
if
(
timer
!=
null
)
{
timer
.
Enabled
=
false
;
timer
.
Interval
=
value
;
timer
.
Enabled
=
true
;
}
}
}
private
float
m_lineTension
=
0.5f
;
/// <summary>
/// 线弯曲程度
/// </summary>
[
Description
(
"线弯曲程度(0-1)"
),
Category
(
"自定义"
)]
public
float
LineTension
{
get
{
return
m_lineTension
;
}
set
{
if
(!(
value
>=
0
&&
value
<=
1
))
{
return
;
}
m_lineTension
=
value
;
Refresh
();
}
}
private
Color
m_lineColor
=
Color
.
FromArgb
(
150
,
73
,
119
,
232
);
[
Description
(
"曲线颜色"
),
Category
(
"自定义"
)]
public
Color
LineColor
{
get
{
return
m_lineColor
;
}
set
{
m_lineColor
=
value
;
Refresh
();
}
}
private
Color
m_gridLineColor
=
Color
.
FromArgb
(
50
,
73
,
119
,
232
);
[
Description
(
"网格线颜色"
),
Category
(
"自定义"
)]
public
Color
GridLineColor
{
get
{
return
m_gridLineColor
;
}
set
{
m_gridLineColor
=
value
;
Refresh
();
}
}
private
Color
m_gridLineTextColor
=
Color
.
FromArgb
(
150
,
73
,
119
,
232
);
[
Description
(
"网格文本颜色"
),
Category
(
"自定义"
)]
public
Color
GridLineTextColor
{
get
{
return
m_gridLineTextColor
;
}
set
{
m_gridLineTextColor
=
value
;
Refresh
();
}
}
public
override
Font
Font
{
get
{
return
base
.
Font
;
}
set
{
base
.
Font
=
value
;
}
}
/// <summary>
/// 数据源,用以缓存所有需要显示的数据
/// </summary>
List
<
KeyValuePair
<
string
,
double
>>
m_dataSource
=
new
List
<
KeyValuePair
<
string
,
double
>>();
/// <summary>
/// 当前需要显示的数据
/// </summary>
List
<
KeyValuePair
<
string
,
double
>>
m_currentSource
=
new
List
<
KeyValuePair
<
string
,
double
>>();
Timer
timer
=
new
Timer
();
/// <summary>
/// 画图区域
/// </summary>
Rectangle
m_drawRect
;
int
m_waveCount
=
0
;
public
UCWaveWithSource
()
{
this
.
SetStyle
(
ControlStyles
.
AllPaintingInWmPaint
,
true
);
this
.
SetStyle
(
ControlStyles
.
DoubleBuffer
,
true
);
this
.
SetStyle
(
ControlStyles
.
ResizeRedraw
,
true
);
this
.
SetStyle
(
ControlStyles
.
Selectable
,
true
);
this
.
SetStyle
(
ControlStyles
.
SupportsTransparentBackColor
,
true
);
this
.
SetStyle
(
ControlStyles
.
UserPaint
,
true
);
this
.
SizeChanged
+=
UCWaveWithSource_SizeChanged
;
this
.
IsShowRect
=
true
;
this
.
RectColor
=
Color
.
FromArgb
(
232
,
232
,
232
);
this
.
FillColor
=
Color
.
FromArgb
(
197
,
229
,
250
);
this
.
RectWidth
=
1
;
this
.
ConerRadius
=
10
;
this
.
IsRadius
=
true
;
this
.
Size
=
new
Size
(
300
,
200
);
timer
.
Interval
=
m_sleepTime
;
timer
.
Tick
+=
timer_Tick
;
this
.
VisibleChanged
+=
UCWave_VisibleChanged
;
}
/// <summary>
/// 添加需要显示的数据
/// </summary>
/// <param name="key">名称</param>
/// <param name="value">值</param>
public
void
AddSource
(
string
key
,
double
value
)
{
m_dataSource
.
Add
(
new
KeyValuePair
<
string
,
double
>(
key
,
value
));
}
void
UCWave_VisibleChanged
(
object
sender
,
EventArgs
e
)
{
if
(!
DesignMode
)
{
timer
.
Enabled
=
this
.
Visible
;
}
}
void
timer_Tick
(
object
sender
,
EventArgs
e
)
{
m_currentSource
=
GetCurrentList
();
m_dataSource
.
RemoveAt
(
0
);
this
.
Refresh
();
}
void
UCWaveWithSource_SizeChanged
(
object
sender
,
EventArgs
e
)
{
m_drawRect
=
new
Rectangle
(
60
,
20
,
this
.
Width
-
80
,
this
.
Height
-
60
);
ResetWaveCount
();
}
protected
override
void
OnPaint
(
PaintEventArgs
e
)
{
base
.
OnPaint
(
e
);
var
g
=
e
.
Graphics
;
g
.
SetGDIHigh
();
int
intLineSplit
=
m_drawRect
.
Height
/
4
;
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
var
pen
=
new
Pen
(
new
SolidBrush
(
m_gridLineColor
),
1
);
// pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
g
.
DrawLine
(
pen
,
m_drawRect
.
Left
,
m_drawRect
.
Bottom
-
1
-
i
*
intLineSplit
,
m_drawRect
.
Right
,
m_drawRect
.
Bottom
-
1
-
i
*
intLineSplit
);
}
if
(
m_currentSource
==
null
||
m_currentSource
.
Count
<=
0
)
{
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
string
strText
=
(
100
/
4
*
i
).
ToString
();
System
.
Drawing
.
SizeF
_numSize
=
g
.
MeasureString
(
strText
,
this
.
Font
);
g
.
DrawString
(
strText
,
Font
,
new
SolidBrush
(
m_gridLineTextColor
),
m_drawRect
.
Left
-
_numSize
.
Width
-
1
,
m_drawRect
.
Bottom
-
1
-
i
*
intLineSplit
-
(
_numSize
.
Height
/
2
));
}
return
;
}
List
<
Point
>
lst1
=
new
List
<
Point
>();
double
dblValue
=
m_currentSource
.
Max
(
p
=>
p
.
Value
);
int
intValue
=
(
int
)
dblValue
;
int
intDivisor
=
(
"1"
.
PadRight
(
intValue
.
ToString
().
Length
-
1
,
'0'
)).
ToInt
();
if
(
intDivisor
<
100
)
intDivisor
=
100
;
int
intTop
=
intValue
;
if
(
intValue
%
intDivisor
!=
0
)
{
intTop
=
(
intValue
/
intDivisor
+
1
)
*
intDivisor
;
}
if
(
intTop
==
0
)
intTop
=
100
;
for
(
int
i
=
0
;
i
<=
4
;
i
++)
{
string
strText
=
(
intTop
/
4
*
i
).
ToString
();
System
.
Drawing
.
SizeF
_numSize
=
g
.
MeasureString
(
strText
,
this
.
Font
);
g
.
DrawString
(
strText
,
Font
,
new
SolidBrush
(
m_gridLineTextColor
),
m_drawRect
.
Left
-
_numSize
.
Width
-
1
,
m_drawRect
.
Bottom
-
1
-
i
*
intLineSplit
-
(
_numSize
.
Height
/
2
));
}
int
intEndX
=
0
;
int
intEndY
=
0
;
for
(
int
i
=
0
;
i
<
m_currentSource
.
Count
;
i
++)
{
intEndX
=
i
*
m_waveActualWidth
+
m_drawRect
.
X
;
intEndY
=
m_drawRect
.
Bottom
-
1
-
(
int
)(
m_currentSource
[
i
].
Value
/
intTop
*
m_drawRect
.
Height
);
lst1
.
Add
(
new
Point
(
intEndX
,
intEndY
));
if
(!
string
.
IsNullOrEmpty
(
m_currentSource
[
i
].
Key
))
{
System
.
Drawing
.
SizeF
_numSize
=
g
.
MeasureString
(
m_currentSource
[
i
].
Key
,
this
.
Font
);
int
txtX
=
intEndX
-
(
int
)(
_numSize
.
Width
/
2
)
+
1
;
g
.
DrawString
(
m_currentSource
[
i
].
Key
,
Font
,
new
SolidBrush
(
m_gridLineTextColor
),
new
PointF
(
txtX
,
m_drawRect
.
Bottom
+
5
));
}
}
int
intFirstY
=
m_drawRect
.
Bottom
-
1
-
(
int
)(
m_currentSource
[
0
].
Value
/
intTop
*
m_drawRect
.
Height
);
GraphicsPath
path1
=
new
GraphicsPath
();
path1
.
AddCurve
(
lst1
.
ToArray
(),
m_lineTension
);
g
.
DrawPath
(
new
Pen
(
new
SolidBrush
(
m_lineColor
),
1
),
path1
);
}
/// <summary>
/// 得到当前需要画图的数据
/// </summary>
/// <returns></returns>
private
List
<
KeyValuePair
<
string
,
double
>>
GetCurrentList
()
{
if
(
m_dataSource
.
Count
<
m_waveCount
)
{
int
intCount
=
m_waveCount
-
m_dataSource
.
Count
;
for
(
int
i
=
0
;
i
<
intCount
;
i
++)
{
m_dataSource
.
Add
(
new
KeyValuePair
<
string
,
double
>(
""
,
0
));
}
}
var
lst
=
m_dataSource
.
GetRange
(
0
,
m_waveCount
);
if
(
lst
.
Count
==
1
)
lst
.
Insert
(
0
,
new
KeyValuePair
<
string
,
double
>(
""
,
0
));
return
lst
;
}
/// <summary>
/// 计算需要显示的个数
/// </summary>
private
void
ResetWaveCount
()
{
m_waveCount
=
m_drawRect
.
Width
/
m_waveWidth
;
m_waveActualWidth
=
m_waveWidth
+
(
m_drawRect
.
Width
%
m_waveWidth
)
/
m_waveCount
;
m_waveCount
++;
if
(
m_dataSource
.
Count
<
m_waveCount
)
{
int
intCount
=
m_waveCount
-
m_dataSource
.
Count
;
for
(
int
i
=
0
;
i
<
intCount
;
i
++)
{
m_dataSource
.
Insert
(
0
,
new
KeyValuePair
<
string
,
double
>(
""
,
0
));
}
}
}
}
}
HZH_Controls/HZH_Controls/HZH_Controls.csproj
查看文件 @
aefbc68
...
@@ -154,6 +154,12 @@
...
@@ -154,6 +154,12 @@
<Compile Include="Controls\Tab\TabControlExt.cs">
<Compile Include="Controls\Tab\TabControlExt.cs">
<SubType>Component</SubType>
<SubType>Component</SubType>
</Compile>
</Compile>
<Compile Include="Controls\Wave\UCWaveChart.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\Wave\UCWave.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Helpers\ControlHelper.cs" />
<Compile Include="Helpers\ControlHelper.cs" />
<Compile Include="Controls\Btn\UCBtnExt.cs">
<Compile Include="Controls\Btn\UCBtnExt.cs">
<SubType>UserControl</SubType>
<SubType>UserControl</SubType>
...
...
HZH_Controls/Test/Form2.Designer.cs
查看文件 @
aefbc68
此文件的差异被折叠,
点击展开。
HZH_Controls/Test/Form2.cs
查看文件 @
aefbc68
...
@@ -19,6 +19,7 @@ namespace Test
...
@@ -19,6 +19,7 @@ namespace Test
private
void
button1_Click
(
object
sender
,
EventArgs
e
)
private
void
button1_Click
(
object
sender
,
EventArgs
e
)
{
{
this
.
ucStep1
.
StepIndex
=
3
;
this
.
ucStep1
.
StepIndex
=
3
;
}
}
private
void
timer1_Tick
(
object
sender
,
EventArgs
e
)
private
void
timer1_Tick
(
object
sender
,
EventArgs
e
)
...
@@ -36,6 +37,27 @@ namespace Test
...
@@ -36,6 +37,27 @@ namespace Test
this
.
ucProcessLine1
.
Value
=
0
;
this
.
ucProcessLine1
.
Value
=
0
;
if
(
this
.
ucProcessLineExt1
.
Value
>=
this
.
ucProcessLineExt1
.
MaxValue
)
if
(
this
.
ucProcessLineExt1
.
Value
>=
this
.
ucProcessLineExt1
.
MaxValue
)
this
.
ucProcessLineExt1
.
Value
=
0
;
this
.
ucProcessLineExt1
.
Value
=
0
;
Random
r
=
new
Random
();
int
i
=
r
.
Next
(
100
,
1000
);
this
.
ucWaveWithSource1
.
AddSource
(
i
.
ToString
(),
i
);
}
private
void
trackBar1_Scroll
(
object
sender
,
EventArgs
e
)
{
this
.
ucWave1
.
WaveSleep
=
trackBar1
.
Value
;
}
private
void
trackBar2_Scroll
(
object
sender
,
EventArgs
e
)
{
this
.
ucWave1
.
WaveHeight
=
trackBar2
.
Value
;
}
private
void
trackBar3_Scroll
(
object
sender
,
EventArgs
e
)
{
this
.
ucWave1
.
WaveWidth
=
trackBar3
.
Value
;
}
}
}
}
}
}
HZH_Controls/Test/FrmTestListView.cs
查看文件 @
aefbc68
...
@@ -31,6 +31,7 @@ namespace Test
...
@@ -31,6 +31,7 @@ namespace Test
this
.
ucListView1
.
Page
=
page
;
this
.
ucListView1
.
Page
=
page
;
//不使用分页控件
//不使用分页控件
//this.ucListView1.DataSource = lstSource;
//this.ucListView1.DataSource = lstSource;
}
}
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论