Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
刘韬
/
HZH_Controls
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 41f076dc
由
HZH
编写于
2019-08-29 11:27:05 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
add Trackbar
1 个父辈
08a3caa0
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
184 行增加
和
0 行删除
HZH_Controls/HZH_Controls/Controls/TrackBar/UCTrackBar.cs
HZH_Controls/HZH_Controls/HZH_Controls.csproj
HZH_Controls/HZH_Controls/Helpers/ControlHelper.cs
HZH_Controls/Test/Form2.Designer.cs
HZH_Controls/HZH_Controls/Controls/TrackBar/UCTrackBar.cs
0 → 100644
查看文件 @
41f076d
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Windows.Forms
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.ComponentModel
;
namespace
HZH_Controls.Controls
{
public
class
UCTrackBar
:
Control
{
[
Description
(
"值改变事件"
),
Category
(
"自定义"
)]
public
event
EventHandler
ValueChanged
;
private
int
dcimalDigits
=
0
;
[
Description
(
"值小数精确位数"
),
Category
(
"自定义"
)]
public
int
DcimalDigits
{
get
{
return
dcimalDigits
;
}
set
{
dcimalDigits
=
value
;
}
}
private
float
lineWidth
=
10
;
[
Description
(
"线宽度"
),
Category
(
"自定义"
)]
public
float
LineWidth
{
get
{
return
lineWidth
;
}
set
{
lineWidth
=
value
;
}
}
private
float
minValue
=
0
;
[
Description
(
"最小值"
),
Category
(
"自定义"
)]
public
float
MinValue
{
get
{
return
minValue
;
}
set
{
if
(
minValue
>
m_value
)
return
;
minValue
=
value
;
this
.
Refresh
();
}
}
private
float
maxValue
=
100
;
[
Description
(
"最大值"
),
Category
(
"自定义"
)]
public
float
MaxValue
{
get
{
return
maxValue
;
}
set
{
if
(
value
<
m_value
)
return
;
maxValue
=
value
;
this
.
Refresh
();
}
}
private
float
m_value
=
0
;
[
Description
(
"值"
),
Category
(
"自定义"
)]
public
float
Value
{
get
{
return
this
.
m_value
;
}
set
{
if
(
value
>
maxValue
||
value
<
minValue
)
return
;
var
v
=
(
float
)
Math
.
Round
((
double
)
value
,
dcimalDigits
);
if
(
value
==
v
)
return
;
this
.
m_value
=
v
;
this
.
Refresh
();
if
(
ValueChanged
!=
null
)
{
ValueChanged
(
this
,
null
);
}
}
}
private
Color
m_lineColor
=
Color
.
FromArgb
(
255
,
77
,
59
);
[
Description
(
"线颜色"
),
Category
(
"自定义"
)]
public
Color
LineColor
{
get
{
return
m_lineColor
;
}
set
{
m_lineColor
=
value
;
this
.
Refresh
();
}
}
RectangleF
m_lineRectangle
;
RectangleF
m_trackRectangle
;
public
UCTrackBar
()
{
this
.
Size
=
new
Size
(
250
,
30
);
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
.
MouseDown
+=
UCTrackBar_MouseDown
;
this
.
MouseMove
+=
UCTrackBar_MouseMove
;
this
.
MouseUp
+=
UCTrackBar_MouseUp
;
}
bool
blnDown
=
false
;
void
UCTrackBar_MouseDown
(
object
sender
,
MouseEventArgs
e
)
{
if
(
m_lineRectangle
.
Contains
(
e
.
Location
)
||
m_trackRectangle
.
Contains
(
e
.
Location
))
{
blnDown
=
true
;
Value
=
((
float
)
e
.
Location
.
X
/
(
float
)
this
.
Width
)
*
(
maxValue
-
minValue
);
}
}
void
UCTrackBar_MouseMove
(
object
sender
,
MouseEventArgs
e
)
{
if
(
blnDown
)
{
Value
=
((
float
)
e
.
Location
.
X
/
(
float
)
this
.
Width
)
*
(
maxValue
-
minValue
);
}
}
void
UCTrackBar_MouseUp
(
object
sender
,
MouseEventArgs
e
)
{
blnDown
=
false
;
}
protected
override
void
OnPaint
(
PaintEventArgs
e
)
{
base
.
OnPaint
(
e
);
Graphics
g
=
e
.
Graphics
;
g
.
SetGDIHigh
();
m_lineRectangle
=
new
RectangleF
(
lineWidth
,
(
this
.
Size
.
Height
-
lineWidth
)
/
2
,
this
.
Size
.
Width
-
lineWidth
*
2
,
lineWidth
);
GraphicsPath
pathLine
=
ControlHelper
.
CreateRoundedRectanglePath
(
m_lineRectangle
,
5
);
g
.
FillPath
(
new
SolidBrush
(
m_lineColor
),
pathLine
);
m_trackRectangle
=
new
RectangleF
(
m_lineRectangle
.
Left
-
lineWidth
+
(((
float
)
m_value
/
(
float
)(
maxValue
-
minValue
))
*
(
this
.
Size
.
Width
-
lineWidth
*
2
)),
(
this
.
Size
.
Height
-
lineWidth
*
2
)
/
2
,
lineWidth
*
2
,
lineWidth
*
2
);
g
.
FillEllipse
(
new
SolidBrush
(
m_lineColor
),
m_trackRectangle
);
g
.
FillEllipse
(
Brushes
.
White
,
new
RectangleF
(
m_trackRectangle
.
X
+
m_trackRectangle
.
Width
/
4
,
m_trackRectangle
.
Y
+
m_trackRectangle
.
Height
/
4
,
m_trackRectangle
.
Width
/
2
,
m_trackRectangle
.
Height
/
2
));
}
}
}
HZH_Controls/HZH_Controls/HZH_Controls.csproj
查看文件 @
41f076d
...
...
@@ -185,6 +185,9 @@
<Compile Include="Controls\Tab\TabControlExt.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\TrackBar\UCTrackBar.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\Wave\UCWaveChart.cs">
<SubType>UserControl</SubType>
</Compile>
...
...
HZH_Controls/HZH_Controls/Helpers/ControlHelper.cs
查看文件 @
41f076d
...
...
@@ -663,5 +663,20 @@ namespace HZH_Controls
roundedRect
.
CloseFigure
();
return
roundedRect
;
}
public
static
GraphicsPath
CreateRoundedRectanglePath
(
RectangleF
rect
,
int
cornerRadius
)
{
GraphicsPath
roundedRect
=
new
GraphicsPath
();
roundedRect
.
AddArc
(
rect
.
X
,
rect
.
Y
,
cornerRadius
*
2
,
cornerRadius
*
2
,
180
,
90
);
roundedRect
.
AddLine
(
rect
.
X
+
cornerRadius
,
rect
.
Y
,
rect
.
Right
-
cornerRadius
*
2
,
rect
.
Y
);
roundedRect
.
AddArc
(
rect
.
X
+
rect
.
Width
-
cornerRadius
*
2
,
rect
.
Y
,
cornerRadius
*
2
,
cornerRadius
*
2
,
270
,
90
);
roundedRect
.
AddLine
(
rect
.
Right
,
rect
.
Y
+
cornerRadius
*
2
,
rect
.
Right
,
rect
.
Y
+
rect
.
Height
-
cornerRadius
*
2
);
roundedRect
.
AddArc
(
rect
.
X
+
rect
.
Width
-
cornerRadius
*
2
,
rect
.
Y
+
rect
.
Height
-
cornerRadius
*
2
,
cornerRadius
*
2
,
cornerRadius
*
2
,
0
,
90
);
roundedRect
.
AddLine
(
rect
.
Right
-
cornerRadius
*
2
,
rect
.
Bottom
,
rect
.
X
+
cornerRadius
*
2
,
rect
.
Bottom
);
roundedRect
.
AddArc
(
rect
.
X
,
rect
.
Bottom
-
cornerRadius
*
2
,
cornerRadius
*
2
,
cornerRadius
*
2
,
90
,
90
);
roundedRect
.
AddLine
(
rect
.
X
,
rect
.
Bottom
-
cornerRadius
*
2
,
rect
.
X
,
rect
.
Y
+
cornerRadius
*
2
);
roundedRect
.
CloseFigure
();
return
roundedRect
;
}
}
}
HZH_Controls/Test/Form2.Designer.cs
查看文件 @
41f076d
...
...
@@ -37,6 +37,7 @@
this
.
label2
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
trackBar3
=
new
System
.
Windows
.
Forms
.
TrackBar
();
this
.
label3
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
ucTrackBar1
=
new
HZH_Controls
.
Controls
.
UCTrackBar
();
this
.
ucProcessWave2
=
new
HZH_Controls
.
Controls
.
UCProcessWave
();
this
.
ucProcessWave1
=
new
HZH_Controls
.
Controls
.
UCProcessWave
();
this
.
ucWaveWithSource1
=
new
HZH_Controls
.
Controls
.
UCWaveWithSource
();
...
...
@@ -135,6 +136,18 @@
this
.
label3
.
TabIndex
=
9
;
this
.
label3
.
Text
=
"波宽"
;
//
// ucTrackBar1
//
this
.
ucTrackBar1
.
LineWidth
=
10
;
this
.
ucTrackBar1
.
Location
=
new
System
.
Drawing
.
Point
(
833
,
403
);
this
.
ucTrackBar1
.
MaxValue
=
100
;
this
.
ucTrackBar1
.
MinValue
=
0
;
this
.
ucTrackBar1
.
Name
=
"ucTrackBar1"
;
this
.
ucTrackBar1
.
Size
=
new
System
.
Drawing
.
Size
(
212
,
32
);
this
.
ucTrackBar1
.
TabIndex
=
12
;
this
.
ucTrackBar1
.
Text
=
"ucTrackBar1"
;
this
.
ucTrackBar1
.
Value
=
100
;
//
// ucProcessWave2
//
this
.
ucProcessWave2
.
BackColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
197
)))),
((
int
)(((
byte
)(
229
)))),
((
int
)(((
byte
)(
250
)))));
...
...
@@ -497,6 +510,7 @@
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
None
;
this
.
BackColor
=
System
.
Drawing
.
Color
.
White
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1438
,
594
);
this
.
Controls
.
Add
(
this
.
ucTrackBar1
);
this
.
Controls
.
Add
(
this
.
ucProcessWave2
);
this
.
Controls
.
Add
(
this
.
ucProcessWave1
);
this
.
Controls
.
Add
(
this
.
ucWaveWithSource1
);
...
...
@@ -567,6 +581,7 @@
private
HZH_Controls
.
Controls
.
UCWaveWithSource
ucWaveWithSource1
;
private
HZH_Controls
.
Controls
.
UCProcessWave
ucProcessWave1
;
private
HZH_Controls
.
Controls
.
UCProcessWave
ucProcessWave2
;
private
HZH_Controls
.
Controls
.
UCTrackBar
ucTrackBar1
;
}
}
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论