线性仪表代码示例
上一节我们通过窗口设计器完成了一下仪表的设计,并给出了模版文件:
这一节我们将通过代码完成,首先在窗口增加一个Guages控件,并给Gauges控件增加一个空白的线性仪表,然后增加一个按钮运行以下代码:
Dim
xg
As
LinearGauge = e.Form.Controls("Guages1").LinearGauge
xg.IsReversed =
True
xg.Orientation = C1.Win.C1Gauge.C1GaugeOrientation.Vertical
xg.AxisStart =
0
xg.BaseOrigin =
0.025
xg.BaseFactor =
0.95
xg.Pointer.Visible =
False
Dim
rct
As
New
GaugeRectangle
rct.Border.LineStyle = C1.Win.C1Gauge.C1GaugeBorderStyle.None
rct.Filling.Color = Color.Black
rct.Viewport.ScaleY =
1.12
xg.FaceShapes.Add(rct)
Dim
pls()
As
String
= {"31HZ",
"63",
"125",
"250",
"500",
"1KHZ",
"2",
"4",
"6",
"16KHZ"}
'频率
Dim
clrs
As
Color() = {color.Khaki, color.DeepSkyBlue, color.SpringGreen,
color.LightSteelBlue,
color.Pink, color.PaleGreen, color.Cyan, color.Gold, color.LightCoral,
color.OldLace}
'各频率对应的颜色
Dim
vls()
As
Double
= {9, 50, 68, 44, 89, 62, 27, 46, 75, 37}
'各频率的默认信号强度
For
idx
As
Integer
=
0
To
9
'增加10个指针
Dim
pt
As
New
GaugePointer()
pt.Value =
False
pt.Name = pls(idx)
pt.Value = vls(idx)
pt.Visible =
False
xg.MorePointers.Add(pt)
Next
For
idx
As
Integer
=
0
To
9
'增加10个Caption
Dim
cp
As
New
GaugeCaption()
cp.Text = pls(idx)
cp.CenterPointY =
1.07
cp.CenterPointX =
0.055 +
idx *
0.1
cp.Font =
New
Font("微软雅黑",
12)
cp.Color = Color.White
xg.FaceShapes.Add(cp)
Next
For
idx
As
Integer
=
0
To
9
'增加10个Marks
Dim
mks
As
New
GaugeMarks
mks.Location =
5
+ idx *
10
mks.ValueColorFalloff = C1.Win.C1Gauge.C1GaugeValueColorFalloff.None
mks.IntervalWidth =
3
mks.Width =
2
mks.Shape = C1.Win.C1Gauge.C1GaugeMarkShape.Round
mks.Length =
7
mks.ValueColors.Add(New
GaugeValueColor(0,
clrs(idx),
1))
'设置ValueColors
mks.ValueColors.Add(New
GaugeValueColor(Double.NaN,
idx, color.DarkGray,
0.5))
xg.Decorators.Add(mks)
Next